LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-18-2013, 04:15 AM   #1
phpshell
Member
 
Registered: Nov 2012
Posts: 46

Rep: Reputation: Disabled
awk and sed on one command


is it possible to do the below output on one command

"73ARAR413:1-1-2-13","4-664-7777",\N,\N,"ADSL_Auto_256-128-ASAM","ADSL_Auto_256-128-ASAM",1,"ADSL","37.0","37.0","6.0","6.0",
"POTS"
"HUWV_SLMNRDFK_AULA096-A:1-0-1-5","11-462-8888","B5004244434D0000","B5004244434D0000"
VDSL2","30.0","30.0","6.0","6.0","POTS"


output should be
73ARAR413:1-1-2-13,46647777
HUWV_SLMNRDFK_AULA096-A:1-0-1-5,114628888



i did many try but need more one command to do that
more file | awk -F, '{print $1","$2}' | sed -e 's/"//g' > 1
73ARAR413:1-1-2-13,4-664-7777
HUWV_SLMNRDFK_AULA096-A:1-0-1-5,11-462-8888
 
Old 06-18-2013, 04:37 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Is your example spread over 4 lines or are there just 2?

Also: put your script/data inside [code] ... [/code] tags it preserves all spacing. If you don't know how: LQ - BB Code List.
 
Old 06-18-2013, 04:51 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,830

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
you do not need more, awk -F, '{print $1","$2}' filename should work.
also sed 's/"//g' can be executed in awk, gsub("\"", ""), so finally you will have:
Code:
awk -F, '{gsub("\"", ""); print $1","$2}' filename
 
Old 06-18-2013, 04:54 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
@pan64: The dashes in field 2 also need removing, assuming there are just 2 lines I came up with this:
Code:
awk -F, '{ gsub(/\"/,"") ; gsub(/-/,"",$2) ; print $1","$2}' infile
But all goes out the window if there are actually 4 lines.....
 
2 members found this post helpful.
Old 06-18-2013, 04:56 AM   #5
phpshell
Member
 
Registered: Nov 2012
Posts: 46

Original Poster
Rep: Reputation: Disabled
it just 2 lines


i am doing the below coding to get the output which very long

Code:
more file | awk -F, '{print $1","$2}' | sed -e 's/"//g' > 1
then

Code:
more 1 | awk -F, '{print $2}' | tr -d "-" > 2
last stage

Code:
paste 2 1 | sed -e 's/\t/,/g' | awk -F, '{print $2,$1}'
 
Old 06-18-2013, 05:01 AM   #6
phpshell
Member
 
Registered: Nov 2012
Posts: 46

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by druuna View Post
@pan64: The dashes in field 2 also need removing, assuming there are just 2 lines I came up with this:
Code:
awk -F, '{ gsub(/\"/,"") ; gsub(/-/,"",$2) ; print $1","$2}' infile
But all goes out the window if there are actually 4 lines.....


many thanks for you man. this is what I am looking for



Quote:
1 members found this post helpful.
 
Old 06-18-2013, 05:29 AM   #7
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Glad to read this is fixed.

Do provide relevant examples the next time you ask a question.

Can you put up the [SOLVED] tag.
- above the first post -> Please Mark this thread as solved if you feel a solution has been provided.
- -or- -
- first post -> Thread Tools -> Mark this thread as solved
 
Old 06-18-2013, 05:55 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,830

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
Oh, yes, but sometimes I feel I should not solve it completely just give a hint or tip.
 
Old 06-18-2013, 09:43 AM   #9
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Another alternative:
Code:
awk -F"\"(,\")?" '{print $2,gensub(/-/,"","g",$3)}' OFS="," file
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Grep/Awk/Sed to get a substring from a command johnjust Programming 5 01-12-2010 08:02 PM
Need help using awk/sed to make this command work blood_ocean Programming 6 09-04-2009 12:06 PM
sed and awk command hot bird Linux - Newbie 3 01-26-2009 10:58 AM
Newbie SED / AWK / Regex command help request Critcho Linux - Newbie 10 03-19-2007 11:22 AM
Sed/Awk command help needed. farmerjoe Programming 3 03-02-2005 11:13 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration