Awk-sed help : to remove first and last line with pattern match:
awk , sed Experts,
I want to remove first and last line after pattern match "vg" :
I am trying : # sed '1d;$d' works fine , but where the last line is not having vg entry it is deleting one line of data.
- So it should check for the pattern vg if present , then it should delete the line , else do nothing.
file1 :
I have tried: the above sed on the file2 , but cutting one data line, that I don't want in the output :
file2 :
Tried:
sed '1d;$d' , but it is deleting last line "disk21122"
How to tell sed to check for the pattern, and then delete, if possible.
Hi Scrutinizer ,
Thanks, but the sed did not work well,
please advise, how not to print, first and last line if pattern matches to the first and last line.
It did not removed the last "vg" pattern matched entry. /dev/vgQ4XT
Hi revri, \| .. | is the same as / .. / , the difference is that the / characters in /dev/vg would need to be escaped:
You can use most characters as long as the first one is escaped:
In the awk piped to sed below I am trying to format file by removing the odd xxxx_digits and whitespace after, then move the even xxxx_digit to the line above it and add a space between them. There may be multiple lines in file but they are in the same format. The Filename_ID line is the last line... (4 Replies)
Input: START
OS:: UNIX
Release: xxx
Version: xxx
END
START
OS:: LINUX
Release: xxx
Version: xxx
END
START
OS:: Windows
Release: xxx
Version: xxx
ENDHere i am trying to get all the information between START and END, only if i could match OS Type.
I can get all the data between the... (3 Replies)
Greetings Experts,
I am in AIX; I have a file generated through awk after processing the input files. Now I need to replace or remove the new-line characters on all lines that doesn't have a ; which is the last character on the line. I tried to use sed 's/\n/ /g' After checking through the... (6 Replies)
I am trying to combine lines with these conditions:
1. First line starts with text of "libname VALUE db2 datasrc" where VALUE can be any text.
2. If condition1 is met then continue to combine lines through a line that ends with a semicolon.
3. Ignore case when matching patterns and remove any... (5 Replies)
the following pattern match works correctly for me
awk '/name="Fruits"/{f=1;next} /"name=Vegetables"/{f=0} f' filename
This works well for me. Id like to temporarily move the match out of the file ( > newfile) and be able to stick it back in the same place at a later time.
Is this... (7 Replies)
I need to grep for the pattern text inside the square brackets which are in red and not in green..my current code greps patterns both of them, which i don't want
Input fileref|XP_002371341.1| oxoacyl-ACP reductase, putative gb|EPT24759.1| 3-ketoacyl-(acyl-carrier-protein) reductase ... (2 Replies)
Data:
Pattern Data Data Data
Data Data Data
Data Data Data
...
With awk, how do I print the pattern matching line, then the subsequent lines following the pattern matching line. Varying number of lines following the pattern matching line. (9 Replies)
Hi How Are you?
I am doing fine!
I need to go now?
I will see you tomorrow!
Basically I need to replace the entire line containing "doing" with a blank line:
I need to the following output:
Hi How Are you?
I need to go now?
I will see you tomorrow!
Thanks in advance.... (1 Reply)
I need to replace the line containing "STAGE_DB" with the line
"STAGE_DB $DB # database that contains the table being loaded ($workingDB)"
Here $DB is passed during the runtime.
How can I do this?
Thanks,
Kousikan (2 Replies)