Scraping line - Using awk or sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Scraping line - Using awk or sed
# 1  
Old 07-23-2013
Scraping line - Using awk or sed

Hello,


Can somone help with this command please?

I have this output pattern in a file. I use a simple awk command to
print each field separated by comma. For example I use this to get the first

Code:
awk -F, "{ print $1 }"

Code:
"ABC=abcdefg,CDF=mnqrst,GGG=hrvyess"

issue:
What I need to do is to get rid of the " " quote at either end of each line
and then print eCh section on a new line

Result should be :
Code:
ABC=abcdefg
CDF=mnqrst
GGG=hrvyess

Thanking you in advance

Last edited by Scott; 07-23-2013 at 07:26 PM.. Reason: Code tags
# 2  
Old 07-23-2013
Code:
awk '{gsub(/"/,X,$1);gsub(/,/,RS,$1);print $1}' file

# 3  
Old 07-23-2013
try
Code:
sed -r 's/^"|"$//g;s/,/\n/g' file
ABC=abcdefg
CDF=mnqrst
GGG=hrvyess

@Yoda: incredible!
# 4  
Old 07-23-2013
I think good old tr command will do here:

Code:
 
echo '"ABC=abcdefg,CDF=mnqrst,GGG=hrvyess"' | tr -d '"' | tr ',' '\n'
ABC=abcdefg
CDF=mnqrst
GGG=hrvyess

Looks more readable, too.
# 5  
Old 07-23-2013
try also (most awk flavors):
Code:
awk '/=/ {gsub(",","\n"); print}' RS="\"" file

or GNU style awks:
Code:
awk '/=/' RS="\"|," file


Last edited by rdrtx1; 07-23-2013 at 08:14 PM..
# 6  
Old 07-23-2013
Some more:

Code:
<file xargs | tr , '\n'

Code:
awk '{gsub(/,/,ORS)}NF' RS=\" file

BSD/GNU grep:
Code:
grep -Eo '[^,"]+' file


--
small variation to rdrtx1's suggestion for gawk / mawk:
Code:
awk NF RS='[",]' file


Last edited by Scrutinizer; 07-23-2013 at 09:33 PM..
# 7  
Old 07-24-2013
Thanks .. I will try all of these and get back to you all
Cheers
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to tail sed and awk in one line?

Hello, I am trying to create an iptables script with tail ,sed and awk. 1st Request: Search keyword "secret" in access.log file 2nd Request: Get first column matching lines (ip address) 3rd Request: Save it to a file This is what I did so far: grep.sh #!/bin/bash while true; do tail... (23 Replies)
Discussion started by: baris35
23 Replies

2. Shell Programming and Scripting

Output on one line using awk or sed

I have a file of 100,000 lines in the below format: answer.bed chr1 957570 957852 NOC2L chr1 976034 976270 PERM1 chr1 976542 976787 PERM1 I need to get each on one line and so far what I have tried doesn't seem to be working. Thank you... (3 Replies)
Discussion started by: cmccabe
3 Replies

3. Shell Programming and Scripting

Multiple line search, replace second line, using awk or sed

All, I appreciate any help you can offer here as this is well beyond my grasp of awk/sed... I have an input file similar to: &LOG &LOG Part: "@DB/TC10000021855/--F" &LOG &LOG &LOG Part: "@DB/TC10000021852/--F" &LOG Cloning_Action: RETAIN &LOG Part: "@DB/TCCP000010713/--A" &LOG &LOG... (5 Replies)
Discussion started by: KarmaPoliceT2
5 Replies

4. 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

5. Shell Programming and Scripting

Command line - awk, sed

My input file gfile values is CTRY=GM&PROJTYPE=SP&PROJECTTYPE=Small+Project If i am giving PROJECTTYPE then it must give Small Project awk -F"&" '{for (i=1; i<=NF; i++) if ($i ~ "^"PAT) {sub ("^"PAT"=", "", $i); sed 's/'+'/""/' $i ; print $i }}' PAT=$1 ... (6 Replies)
Discussion started by: nag_sathi
6 Replies

6. Shell Programming and Scripting

sed or awk to replace a value in a certain line.

I have an input like following. *DEFINE_CURVE_TITLE Force for tool binder $# lcid sidr sfa sfo offa offo dattyp 3 0 1 .000000 125.00000 0.000 0.000 0 $# a1 ... (5 Replies)
Discussion started by: hamnsan
5 Replies

7. Shell Programming and Scripting

Line Parsing using sed and awk

Hi Guys, I need help with processing data in a file, line by line. My file test.txt has X_Building_X5946/X0 BUT/U_msp/RdBuMon_d2_B_00 BUT/U_msp/FfRmDaMix_d2_Pi3 Test_Long xp=849.416 yp=245.82 xn=849.488 yn=245.82 w=0.476 l=0.072 fault_layer="Al_T01_Mod" $ $X=849416 $Y=245582... (2 Replies)
Discussion started by: naveen@
2 Replies

8. Shell Programming and Scripting

awk;sed appending line to previous line....

I know this has been asked before but I just can't parse the syntax as explained. I have a set of files that has user information spread out over two lines that I wish to merge into one: User1NameLast User1NameFirst User1Address E-Mail:User1email User2NameLast User2NameFirst User2Address... (11 Replies)
Discussion started by: walkerwheeler
11 Replies

9. Shell Programming and Scripting

Read logline line by line with awk/sed

Hello, I have a logfile which is in this format: 1211667249500#3265 1211667266687#2875 1211667270781#1828 Is there a way to read the logfile line by line every time I execute the code and put the two numbers in the line in two separate variables? Something like: 1211667249500#3265... (7 Replies)
Discussion started by: dejavu88
7 Replies
Login or Register to Ask a Question