Get the list with sed or awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get the list with sed or awk
# 8  
Old 12-05-2012
Quote:
Originally Posted by yanglei_fage
I understand it partly, if change zzz D to a variable, can we get it eg: VAR="zzz D"
I am not clear what you are saying.. Smilie

As per your requirement code prints lines after if it finds [General] or [zzz D].

Here i just use a for printing the expected result.

Quote:
Originally Posted by michaelrozar17
Through Sed..
Code:
$ sed -n 'H;${
x
s/[^]]*]\n\([^[]*\).*\[zzz D\]\n\([^[]*\)\n.*/\1\2/p
}' inputfile

This will fail if it file starts with any other tags than [General].

And if you are saying as you want to pass variable as Jotne pointed out then use.

Code:
awk -v var="[zzz D]" '/^\[/{a=""}
a{print}
/\[General\]/ || $0 == var{a=1}' file




Quote:
Originally Posted by Jotne
Code:
awk '/^\[/{a=""}
a{print}
$0~"[General]" || $0~var {a=1}' var="[zzz D]" file

Edit: This gives to much, not sure whats wrong
@Jotne -
you can do like /\[General\]/ || $0 == var

Last edited by pamu; 12-05-2012 at 02:33 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get some data from a list, using grep or sed

Hi, my dear friends, I have to use very frequently the command of qsum to check the free node for job submitting. However, qsum always shows all the nodes regardless of their status. occupied p1 100000mb 48:00:00 1 p72 51200mb -- 1 p73 51200mb -- ... (4 Replies)
Discussion started by: liuzhencc
4 Replies

2. Shell Programming and Scripting

How to find the X highest values in a list depending on the values of another list with bash/awk?

Hi everyone, This is an exemple of inpout.txt file (a "," delimited text file which can be open as csv file): ID, Code, Value, Store SP|01, AABBCDE, 15, 3 SP|01, AABBCDE, 14, 2 SP|01, AABBCDF, 13, 2 SP|01, AABBCDE, 16, 3 SP|02, AABBCED, 15, 2 SP|01, AABBCDF, 12, 3 SP|01, AABBCDD,... (1 Reply)
Discussion started by: jeremy589
1 Replies

3. Shell Programming and Scripting

sed and awk giving error ./sample.sh: line 13: sed: command not found

Hi, I am running a script sample.sh in bash environment .In the script i am using sed and awk commands which when executed individually from terminal they are getting executed normally but when i give these sed and awk commands in the script it is giving the below errors :- ./sample.sh: line... (12 Replies)
Discussion started by: satishmallidi
12 Replies

4. UNIX for Advanced & Expert Users

Argument list too long w/ sed

Hi all, I am using GNU sed (named gsed under macports) in OSX. I have a directory with a series of files named pool_01.jpg through pool_78802.jpg. I am trying to use this command to rename the files to their checksum + extension. md5sum * | gsed -e 's/\(*\) \(.*\(\..*\)\)$/mv -v \2 \1\3/e' ... (3 Replies)
Discussion started by: openthomas
3 Replies

5. Shell Programming and Scripting

sed/awk script to parse list of bandwidth rules

Hello all gurus, I have a long list of rules as below: 20 name:abc addr:203.45.247.247/255.255.255.255 WDW-THRESH:12 BW-OUT:10000000bps BW-IN:15000000bps STATSDEVICE:test247 STATS:Enabled (4447794/0) <IN OUT> 25 name:xyz160 addr:203.45.233.160/255.255.255.224 STATSDEVICE:test160... (3 Replies)
Discussion started by: sb245
3 Replies

6. Shell Programming and Scripting

Converting a line into a list using awk or sed

Hello, I am trying to convert a line into a list using awk or sed. Line: 345 897 567 098 123 output: 345 897 567 098 123 thanks (7 Replies)
Discussion started by: smarones
7 Replies

7. Shell Programming and Scripting

Replacing or removing a long list of pattern by using awk or sed

Input: >abc|123456|def|EXIT| >abc|203456|def|EXIT2| >abc|234056|def|EXIT3| >abc|340056|def|EXIT4| >abc|456000|def|EXIT5| . . . Output: def|EXIT| def|EXIT2| def|EXIT3| def|EXIT4| def|EXIT5| . . My try code: (9 Replies)
Discussion started by: patrick87
9 Replies

8. Shell Programming and Scripting

sed/awk help to match list of patterns and remove from org file

Hi, From the pattern mentioned below remove lines based on pattern range. Conditions 1 Look For all lines starting with ALTER TABLE and Ending with ; and contains the word MOVE.I wanto to remove these lines from the file sample below. Note : The above pattern list could be found in... (1 Reply)
Discussion started by: rajan_san
1 Replies
Login or Register to Ask a Question