How to delete everything present on left (or right) of a substring?
Hello,
I have list of lines from which i am trying to pick a sub string and want to put that into a csv file, the sub string i want to extract is at the middle of the line, i was wondering how can i delete everything that is present left/right of a sub string. I have tried sed, cut and awk, but i couldn't get desired results.
Below are few lines, from which i am trying to pick PXCNUMBER_1 and append them to a csv file.
using awk and cut i got this result, due to some inconsistency in the lines i failed to pick the PXCNUMBERS_1, precisely as you could see there is MSGS_ in the last line before PXCNUMBERS_1 .
Desired results are
I know i could use sed to replace MSGS in the last line to empty, but there are more lines than i have showed above, and i was also curious to know if there is any command to cut everything left/right of a sub string. any pointers would be great help
match(s,r)
Returns the index of the first longest match of regular expression r in string s. Returns 0 if no match. As a side effect, RSTART is set to the return value. RLENGTH is set to the length of the match or -1 if no match. If the empty string is matched, RLENGTH is set to 0, and 1 is returned if the match is at the front, and length(s)+1 is returned if the match is at the back.
The match searches $0 for your target string PCX..._1 (the ellipsis replaced by [^_]*, i.e. non-"_" characters), and, if found, sets RSTART and RLENGTH accordingly for immediate use by the substr function.
BTW, that awk scriptlet doesn't need the upfront grep (as it checks lines for PROTOBUF_DIRS already and on its own), and it can be adapted to also make the uniq redundant.
I know that it is possible to login into the HMC console and view all the specs like, how much CPU/RAM every LPAR has.
But how can I check how much the whole P7 has in total and how much is left to creat a new LPAR:wall: (5 Replies)
here is what i want to achieve.. i have a file with below contents
cat fileName
blah blah blah
.
.DROP this
REJECT that
.
--sport 7800 -j REJECT --reject-with icmp-port-unreachable
--dport 7800 -j REJECT --reject-with icmp-port-unreachable
.
.
.
more blah blah blah
--dport 3306... (14 Replies)
Hi guys,
I need to use awk to join 2 files
file_1
A 001
B 002
C 003
file_2
A XX1
B XX2
output desired
A 001 XX1
B 002 missing
C 003 XX2
thank you! (2 Replies)
Need unix commands to delete records from one file if the same record present in another file...
just like join ... if the record present in both files.. delete from first file or delete the particular record and write the unmatched records to new file..
tried with grep and while... (6 Replies)
I have two files
File1
====
1|2000-00-00|2010-02-02||
2| 00:00:00|2012-02-24||
3|2000-00-00|2011-02-02||
File2
====
2000-00-00
00:00:00
I want the delete the patterns which are found in file 2 from file 1,
Expected output:
File1
==== (5 Replies)
I am passing input string,length, and the pad character.
input string=123
Pad char=#
Length=6
then the output should be:
###123
How we can do this?
Thanks (5 Replies)
HI,
if a String is present in file1.txt, i want to delete that String from file2.txt.
How can i do this??
I am sure that the file1.txt is a subset of file2.txt. (2 Replies)
Hi all,
A very strange problem I have this morning with my Solaris 8.
I have a FS full, I deleted some files but the system doesn't seems to reallocate the free space (I'm using Veritas):
df -k :
/dev/vx/dsk/dlds02vg/dlds02oralv 4194304 4194304 0 100% /dlds02/lds/oracle
... (4 Replies)
hi
i have a file which is like this :
aab ghj
ghj lsklk
lklkl;
ashjd
kjs
alskj
How do i remove the spaces from the beginning of a line so that all lines are indented to the left? (1 Reply)
I have a script which loop through a directory then report any file matches the given pattern,
say, the pattern is "a2006", this file would be returned
a20061101.txt
I would like to know how can I get the remaining of the filename, so
a20061101txt - a2006 = 1101.txt
Can anybody help? Thank... (2 Replies)