how to separate line using awk
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
How can I separate the line as below in a csv file:
(12,'hello','this girl,is lovely(adorable rn actually)',goodbye),(13,'hello','this fruit,is super tasty (sweet actually)',goodbye)
to the below as 2 different rows:
(12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
(13,'hello','this fruit,is super tasty (sweet actually)',goodbye)
I tried using:
awk -F"[()]" 'print $2' test.csv
but it didn't work and lost a few rows.
This data is actually a SQL query and I need to extract the data and convert it into different rows using the comma after ) and before ( as row seperator
awk newlines
add a comment |Â
up vote
2
down vote
favorite
How can I separate the line as below in a csv file:
(12,'hello','this girl,is lovely(adorable rn actually)',goodbye),(13,'hello','this fruit,is super tasty (sweet actually)',goodbye)
to the below as 2 different rows:
(12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
(13,'hello','this fruit,is super tasty (sweet actually)',goodbye)
I tried using:
awk -F"[()]" 'print $2' test.csv
but it didn't work and lost a few rows.
This data is actually a SQL query and I need to extract the data and convert it into different rows using the comma after ) and before ( as row seperator
awk newlines
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
How can I separate the line as below in a csv file:
(12,'hello','this girl,is lovely(adorable rn actually)',goodbye),(13,'hello','this fruit,is super tasty (sweet actually)',goodbye)
to the below as 2 different rows:
(12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
(13,'hello','this fruit,is super tasty (sweet actually)',goodbye)
I tried using:
awk -F"[()]" 'print $2' test.csv
but it didn't work and lost a few rows.
This data is actually a SQL query and I need to extract the data and convert it into different rows using the comma after ) and before ( as row seperator
awk newlines
How can I separate the line as below in a csv file:
(12,'hello','this girl,is lovely(adorable rn actually)',goodbye),(13,'hello','this fruit,is super tasty (sweet actually)',goodbye)
to the below as 2 different rows:
(12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
(13,'hello','this fruit,is super tasty (sweet actually)',goodbye)
I tried using:
awk -F"[()]" 'print $2' test.csv
but it didn't work and lost a few rows.
This data is actually a SQL query and I need to extract the data and convert it into different rows using the comma after ) and before ( as row seperator
awk newlines
edited Jan 22 at 1:29
asked Jan 22 at 1:22
Derek
133
133
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
This awk command can do what you want:
awk -F '),' ' print $1")" "n" $2' source.csv
Result:
(12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
(13,'hello','this fruit,is super tasty (sweet actually)',goodbye)
add a comment |Â
up vote
2
down vote
With GNU sed
(and your sample input saved in a file called ./input
):
$ sed -e 's/),(/)n(/g' ./input
(12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
(13,'hello','this fruit,is super tasty (sweet actually)',goodbye)
This changes the comma in every ),(
to a newline.
WARNING: If that character sequence occurs inside your actual data, it will be changed there too.
You could do the same in awk
, but there's little or no advantage over using sed
:
$ awk 'gsub(/),(/,")n(",$0)' ./input
(12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
(13,'hello','this fruit,is super tasty (sweet actually)',goodbye)
Unless you're going to do further processing on the input line that requires awk
features, just use sed
.
Thanks alot for your help..really appreciate it! thanks :)
â Derek
Jan 22 at 18:54
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
This awk command can do what you want:
awk -F '),' ' print $1")" "n" $2' source.csv
Result:
(12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
(13,'hello','this fruit,is super tasty (sweet actually)',goodbye)
add a comment |Â
up vote
1
down vote
accepted
This awk command can do what you want:
awk -F '),' ' print $1")" "n" $2' source.csv
Result:
(12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
(13,'hello','this fruit,is super tasty (sweet actually)',goodbye)
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
This awk command can do what you want:
awk -F '),' ' print $1")" "n" $2' source.csv
Result:
(12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
(13,'hello','this fruit,is super tasty (sweet actually)',goodbye)
This awk command can do what you want:
awk -F '),' ' print $1")" "n" $2' source.csv
Result:
(12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
(13,'hello','this fruit,is super tasty (sweet actually)',goodbye)
answered Jan 22 at 5:35
George Udosen
1,112318
1,112318
add a comment |Â
add a comment |Â
up vote
2
down vote
With GNU sed
(and your sample input saved in a file called ./input
):
$ sed -e 's/),(/)n(/g' ./input
(12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
(13,'hello','this fruit,is super tasty (sweet actually)',goodbye)
This changes the comma in every ),(
to a newline.
WARNING: If that character sequence occurs inside your actual data, it will be changed there too.
You could do the same in awk
, but there's little or no advantage over using sed
:
$ awk 'gsub(/),(/,")n(",$0)' ./input
(12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
(13,'hello','this fruit,is super tasty (sweet actually)',goodbye)
Unless you're going to do further processing on the input line that requires awk
features, just use sed
.
Thanks alot for your help..really appreciate it! thanks :)
â Derek
Jan 22 at 18:54
add a comment |Â
up vote
2
down vote
With GNU sed
(and your sample input saved in a file called ./input
):
$ sed -e 's/),(/)n(/g' ./input
(12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
(13,'hello','this fruit,is super tasty (sweet actually)',goodbye)
This changes the comma in every ),(
to a newline.
WARNING: If that character sequence occurs inside your actual data, it will be changed there too.
You could do the same in awk
, but there's little or no advantage over using sed
:
$ awk 'gsub(/),(/,")n(",$0)' ./input
(12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
(13,'hello','this fruit,is super tasty (sweet actually)',goodbye)
Unless you're going to do further processing on the input line that requires awk
features, just use sed
.
Thanks alot for your help..really appreciate it! thanks :)
â Derek
Jan 22 at 18:54
add a comment |Â
up vote
2
down vote
up vote
2
down vote
With GNU sed
(and your sample input saved in a file called ./input
):
$ sed -e 's/),(/)n(/g' ./input
(12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
(13,'hello','this fruit,is super tasty (sweet actually)',goodbye)
This changes the comma in every ),(
to a newline.
WARNING: If that character sequence occurs inside your actual data, it will be changed there too.
You could do the same in awk
, but there's little or no advantage over using sed
:
$ awk 'gsub(/),(/,")n(",$0)' ./input
(12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
(13,'hello','this fruit,is super tasty (sweet actually)',goodbye)
Unless you're going to do further processing on the input line that requires awk
features, just use sed
.
With GNU sed
(and your sample input saved in a file called ./input
):
$ sed -e 's/),(/)n(/g' ./input
(12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
(13,'hello','this fruit,is super tasty (sweet actually)',goodbye)
This changes the comma in every ),(
to a newline.
WARNING: If that character sequence occurs inside your actual data, it will be changed there too.
You could do the same in awk
, but there's little or no advantage over using sed
:
$ awk 'gsub(/),(/,")n(",$0)' ./input
(12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
(13,'hello','this fruit,is super tasty (sweet actually)',goodbye)
Unless you're going to do further processing on the input line that requires awk
features, just use sed
.
answered Jan 22 at 2:53
cas
37.7k44393
37.7k44393
Thanks alot for your help..really appreciate it! thanks :)
â Derek
Jan 22 at 18:54
add a comment |Â
Thanks alot for your help..really appreciate it! thanks :)
â Derek
Jan 22 at 18:54
Thanks alot for your help..really appreciate it! thanks :)
â Derek
Jan 22 at 18:54
Thanks alot for your help..really appreciate it! thanks :)
â Derek
Jan 22 at 18:54
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f418721%2fhow-to-separate-line-using-awk%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password