parse linux paths as columns in a .csv file bash
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I have a .csv data file which I have manipulated to look like this:
-------------PATH AND FILE NAME--------,USER--,DATE-----,TIME---,STATUS
/Proj/abc/app/app_pit/conf/HUB_TEST.apx,uJones,4/24/2018,5:55:58,OK
/Proj/abc/app/app_pit/conf/test_acqit1.apx,uSmith,3/8/2018,10:16:41,OK
/Proj/abc/app/app_pit/conf/test_bkfs.apx,uHarry,/26/2018,9:47:03,OK
Which was fantastic! Until, I got some feedback and a request to subdivide the "PATH AND FILE NAME" column as such:
LB,-PROJ---,FILENAME----,USER--,DATE-----,TIME---,STATUS
app,app_pit,HUB_TEST.apx,uJones,4/24/2018,5:55:58,OK
app,app_pit,test_acqit1.apx,uSmith,3/8/2018,10:16:41,OK
app,app_pit,test_bkfs.apx,uHarry,/26/2018,9:47:03,OK
Omitting "/Proj/abc" from all records and removing "conf" from the path
I am very new at this.. I tried many different awk, sed, tr, etc apps but cant seem to get this right. Perhaps there is some looping logic to employ here??? THANKS!
awk csv text-formatting
add a comment |Â
up vote
0
down vote
favorite
I have a .csv data file which I have manipulated to look like this:
-------------PATH AND FILE NAME--------,USER--,DATE-----,TIME---,STATUS
/Proj/abc/app/app_pit/conf/HUB_TEST.apx,uJones,4/24/2018,5:55:58,OK
/Proj/abc/app/app_pit/conf/test_acqit1.apx,uSmith,3/8/2018,10:16:41,OK
/Proj/abc/app/app_pit/conf/test_bkfs.apx,uHarry,/26/2018,9:47:03,OK
Which was fantastic! Until, I got some feedback and a request to subdivide the "PATH AND FILE NAME" column as such:
LB,-PROJ---,FILENAME----,USER--,DATE-----,TIME---,STATUS
app,app_pit,HUB_TEST.apx,uJones,4/24/2018,5:55:58,OK
app,app_pit,test_acqit1.apx,uSmith,3/8/2018,10:16:41,OK
app,app_pit,test_bkfs.apx,uHarry,/26/2018,9:47:03,OK
Omitting "/Proj/abc" from all records and removing "conf" from the path
I am very new at this.. I tried many different awk, sed, tr, etc apps but cant seem to get this right. Perhaps there is some looping logic to employ here??? THANKS!
awk csv text-formatting
Are/Proj/abc/
and/conf/
literal constant strings here? or do they vary from record to record?
â steeldriver
Jun 14 at 15:12
where doesLB,-PROJ---
come from?
â RomanPerekhrest
Jun 14 at 15:14
They appear to be very constant. Thanks!
â SSDdude
Jun 14 at 15:15
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a .csv data file which I have manipulated to look like this:
-------------PATH AND FILE NAME--------,USER--,DATE-----,TIME---,STATUS
/Proj/abc/app/app_pit/conf/HUB_TEST.apx,uJones,4/24/2018,5:55:58,OK
/Proj/abc/app/app_pit/conf/test_acqit1.apx,uSmith,3/8/2018,10:16:41,OK
/Proj/abc/app/app_pit/conf/test_bkfs.apx,uHarry,/26/2018,9:47:03,OK
Which was fantastic! Until, I got some feedback and a request to subdivide the "PATH AND FILE NAME" column as such:
LB,-PROJ---,FILENAME----,USER--,DATE-----,TIME---,STATUS
app,app_pit,HUB_TEST.apx,uJones,4/24/2018,5:55:58,OK
app,app_pit,test_acqit1.apx,uSmith,3/8/2018,10:16:41,OK
app,app_pit,test_bkfs.apx,uHarry,/26/2018,9:47:03,OK
Omitting "/Proj/abc" from all records and removing "conf" from the path
I am very new at this.. I tried many different awk, sed, tr, etc apps but cant seem to get this right. Perhaps there is some looping logic to employ here??? THANKS!
awk csv text-formatting
I have a .csv data file which I have manipulated to look like this:
-------------PATH AND FILE NAME--------,USER--,DATE-----,TIME---,STATUS
/Proj/abc/app/app_pit/conf/HUB_TEST.apx,uJones,4/24/2018,5:55:58,OK
/Proj/abc/app/app_pit/conf/test_acqit1.apx,uSmith,3/8/2018,10:16:41,OK
/Proj/abc/app/app_pit/conf/test_bkfs.apx,uHarry,/26/2018,9:47:03,OK
Which was fantastic! Until, I got some feedback and a request to subdivide the "PATH AND FILE NAME" column as such:
LB,-PROJ---,FILENAME----,USER--,DATE-----,TIME---,STATUS
app,app_pit,HUB_TEST.apx,uJones,4/24/2018,5:55:58,OK
app,app_pit,test_acqit1.apx,uSmith,3/8/2018,10:16:41,OK
app,app_pit,test_bkfs.apx,uHarry,/26/2018,9:47:03,OK
Omitting "/Proj/abc" from all records and removing "conf" from the path
I am very new at this.. I tried many different awk, sed, tr, etc apps but cant seem to get this right. Perhaps there is some looping logic to employ here??? THANKS!
awk csv text-formatting
asked Jun 14 at 15:06
SSDdude
544
544
Are/Proj/abc/
and/conf/
literal constant strings here? or do they vary from record to record?
â steeldriver
Jun 14 at 15:12
where doesLB,-PROJ---
come from?
â RomanPerekhrest
Jun 14 at 15:14
They appear to be very constant. Thanks!
â SSDdude
Jun 14 at 15:15
add a comment |Â
Are/Proj/abc/
and/conf/
literal constant strings here? or do they vary from record to record?
â steeldriver
Jun 14 at 15:12
where doesLB,-PROJ---
come from?
â RomanPerekhrest
Jun 14 at 15:14
They appear to be very constant. Thanks!
â SSDdude
Jun 14 at 15:15
Are
/Proj/abc/
and /conf/
literal constant strings here? or do they vary from record to record?â steeldriver
Jun 14 at 15:12
Are
/Proj/abc/
and /conf/
literal constant strings here? or do they vary from record to record?â steeldriver
Jun 14 at 15:12
where does
LB,-PROJ---
come from?â RomanPerekhrest
Jun 14 at 15:14
where does
LB,-PROJ---
come from?â RomanPerekhrest
Jun 14 at 15:14
They appear to be very constant. Thanks!
â SSDdude
Jun 14 at 15:15
They appear to be very constant. Thanks!
â SSDdude
Jun 14 at 15:15
add a comment |Â
5 Answers
5
active
oldest
votes
up vote
1
down vote
Ignoring the header, and assuming that the text in the file has no spaces at the start of the line (it has in your question):
$ sed -e 's@/Proj/abc/([^/]*)/([^/]*)/conf/@1,2,@' file
-------------PATH AND FILE NAME--------,USER--,DATE-----,TIME---,STATUS
app,app_pit,HUB_TEST.apx,uJones,4/24/2018,5:55:58,OK
app,app_pit,test_acqit1.apx,uSmith,3/8/2018,10:16:41,OK
app,app_pit,test_bkfs.apx,uHarry,/26/2018,9:47:03,OK
The sed
command captures the app
and app_pit
strings (which I assume can vary), and replaces the path in the original data with these with commas in-between while leaving the last bit of the path as its own field.
Redirect this to a new file and then fix the header (if needed).
@steeldriver Ah, theconf
has to go too. I will avoid hardcodingapp
there though. Thanks!
â Kusalananda
Jun 14 at 15:23
1
Yes good idea - it's not clear how variable the OP's records are
â steeldriver
Jun 14 at 15:27
add a comment |Â
up vote
1
down vote
sed -e 's|-------------PATH AND FILE NAME--------,USER--,DATE-----,TIME---,STATUS|LB,-PROJ---,FILENAME----,USER--,DATE-----,TIME---,STATUS|' -e 's|/Proj/abc/||g' -e 's|/conf||g' -e 's|/|,|2' -e 's|/|,|1' file
Just an extended set of stream replacements.
The first changes the first line to starting with the string beginning with LB
that you want.
The second removes /Proj/abc/.
The third removes /conf.
The fourth and fifth replace the 2nd and 1st forward slashes with commas.
Output:
LB,-PROJ---,FILENAME----,USER--,DATE-----,TIME---,STATUS
app,app_pit,HUB_TEST.apx,uJones,4/24/2018,5:55:58,OK
app,app_pit,test_acqit1.apx,uSmith,3/8/2018,10:16:41,OK
app,app_pit,test_bkfs.apx,uHarry,/26/2018,9:47:03,OK
Hello Nasir and thanks for your reply. I notice your solution has still has "PATH and FILENAME" which needs to be divided into LB, PROJ, FILENAME but neither way is printing the header. The data looks great! Any ideas?
â SSDdude
Jun 19 at 14:08
@SSDdude Thesed -e
only sends the changes to std output and it changes "PATH and FILENAME" to LB, PROJ, FILENAME when I do it on my machine with the output as what's above in my answer. If you want the changes to the file, add-i
aftersed
. Are you usinggnu sed
?
â Nasir Riley
Jun 19 at 14:33
add a comment |Â
up vote
0
down vote
Note that this will catch fire if any of the filenames have a ,
or /
in them:
$ awk -F "[/,]" -v OFS="," 'BEGIN print "LB", "-PROJ--", "FILENAME----", "USER--", "DATA-----", "TIME---", "STATUS" NR!=1print $4,$5,$7,$8,$9"/"$10"/"$11,$12,$13' input
LB,-PROJ--,FILENAME----,USER--,DATA-----,TIME---,STATUS
app,app_pit,HUB_TEST.apx,uJones,4/24/2018,5:55:58,OK
app,app_pit,test_acqit1.apx,uSmith,3/8/2018,10:16:41,OK
app,app_pit,test_bkfs.apx,uHarry,/26/2018,9:47:03,OK
add a comment |Â
up vote
0
down vote
Awk
solution:
awk 'BEGIN FS = OFS = ","
NR == 1 $1 = "LB,-PROJ---,FILENAME----"
NR > 1conf)", "", $1);
gsub("/", ",", $1)
1' file
The output:
LB,-PROJ---,FILENAME----,USER--,DATE-----,TIME---,STATUS
app,app_pit,HUB_TEST.apx,uJones,4/24/2018,5:55:58,OK
app,app_pit,test_acqit1.apx,uSmith,3/8/2018,10:16:41,OK
app,app_pit,test_bkfs.apx,uHarry,/26/2018,9:47:03,OK
add a comment |Â
up vote
0
down vote
SOLVED!
sed -e 's|-------------PATH AND FILE NAME--------,USER--,DATE-----,TIME---,STATUS|LB,-PROJ---,FILENAME----,USER--,DATE-----,TIME---,STATUS|' -e 's|/Proj/abc/||g' -e 's|/conf||g' -e 's|/|,|2' -e 's|/|,|1' file
Thanks Nasir Riley, your sed solution worked flawlessly!!
The right thing to do here is to accept Nasir's solution (click the checkbox), not repeat their answer.
â Jeff Schaller
Jun 19 at 17:13
add a comment |Â
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Ignoring the header, and assuming that the text in the file has no spaces at the start of the line (it has in your question):
$ sed -e 's@/Proj/abc/([^/]*)/([^/]*)/conf/@1,2,@' file
-------------PATH AND FILE NAME--------,USER--,DATE-----,TIME---,STATUS
app,app_pit,HUB_TEST.apx,uJones,4/24/2018,5:55:58,OK
app,app_pit,test_acqit1.apx,uSmith,3/8/2018,10:16:41,OK
app,app_pit,test_bkfs.apx,uHarry,/26/2018,9:47:03,OK
The sed
command captures the app
and app_pit
strings (which I assume can vary), and replaces the path in the original data with these with commas in-between while leaving the last bit of the path as its own field.
Redirect this to a new file and then fix the header (if needed).
@steeldriver Ah, theconf
has to go too. I will avoid hardcodingapp
there though. Thanks!
â Kusalananda
Jun 14 at 15:23
1
Yes good idea - it's not clear how variable the OP's records are
â steeldriver
Jun 14 at 15:27
add a comment |Â
up vote
1
down vote
Ignoring the header, and assuming that the text in the file has no spaces at the start of the line (it has in your question):
$ sed -e 's@/Proj/abc/([^/]*)/([^/]*)/conf/@1,2,@' file
-------------PATH AND FILE NAME--------,USER--,DATE-----,TIME---,STATUS
app,app_pit,HUB_TEST.apx,uJones,4/24/2018,5:55:58,OK
app,app_pit,test_acqit1.apx,uSmith,3/8/2018,10:16:41,OK
app,app_pit,test_bkfs.apx,uHarry,/26/2018,9:47:03,OK
The sed
command captures the app
and app_pit
strings (which I assume can vary), and replaces the path in the original data with these with commas in-between while leaving the last bit of the path as its own field.
Redirect this to a new file and then fix the header (if needed).
@steeldriver Ah, theconf
has to go too. I will avoid hardcodingapp
there though. Thanks!
â Kusalananda
Jun 14 at 15:23
1
Yes good idea - it's not clear how variable the OP's records are
â steeldriver
Jun 14 at 15:27
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Ignoring the header, and assuming that the text in the file has no spaces at the start of the line (it has in your question):
$ sed -e 's@/Proj/abc/([^/]*)/([^/]*)/conf/@1,2,@' file
-------------PATH AND FILE NAME--------,USER--,DATE-----,TIME---,STATUS
app,app_pit,HUB_TEST.apx,uJones,4/24/2018,5:55:58,OK
app,app_pit,test_acqit1.apx,uSmith,3/8/2018,10:16:41,OK
app,app_pit,test_bkfs.apx,uHarry,/26/2018,9:47:03,OK
The sed
command captures the app
and app_pit
strings (which I assume can vary), and replaces the path in the original data with these with commas in-between while leaving the last bit of the path as its own field.
Redirect this to a new file and then fix the header (if needed).
Ignoring the header, and assuming that the text in the file has no spaces at the start of the line (it has in your question):
$ sed -e 's@/Proj/abc/([^/]*)/([^/]*)/conf/@1,2,@' file
-------------PATH AND FILE NAME--------,USER--,DATE-----,TIME---,STATUS
app,app_pit,HUB_TEST.apx,uJones,4/24/2018,5:55:58,OK
app,app_pit,test_acqit1.apx,uSmith,3/8/2018,10:16:41,OK
app,app_pit,test_bkfs.apx,uHarry,/26/2018,9:47:03,OK
The sed
command captures the app
and app_pit
strings (which I assume can vary), and replaces the path in the original data with these with commas in-between while leaving the last bit of the path as its own field.
Redirect this to a new file and then fix the header (if needed).
edited Jun 14 at 15:29
answered Jun 14 at 15:14
Kusalananda
101k13199312
101k13199312
@steeldriver Ah, theconf
has to go too. I will avoid hardcodingapp
there though. Thanks!
â Kusalananda
Jun 14 at 15:23
1
Yes good idea - it's not clear how variable the OP's records are
â steeldriver
Jun 14 at 15:27
add a comment |Â
@steeldriver Ah, theconf
has to go too. I will avoid hardcodingapp
there though. Thanks!
â Kusalananda
Jun 14 at 15:23
1
Yes good idea - it's not clear how variable the OP's records are
â steeldriver
Jun 14 at 15:27
@steeldriver Ah, the
conf
has to go too. I will avoid hardcoding app
there though. Thanks!â Kusalananda
Jun 14 at 15:23
@steeldriver Ah, the
conf
has to go too. I will avoid hardcoding app
there though. Thanks!â Kusalananda
Jun 14 at 15:23
1
1
Yes good idea - it's not clear how variable the OP's records are
â steeldriver
Jun 14 at 15:27
Yes good idea - it's not clear how variable the OP's records are
â steeldriver
Jun 14 at 15:27
add a comment |Â
up vote
1
down vote
sed -e 's|-------------PATH AND FILE NAME--------,USER--,DATE-----,TIME---,STATUS|LB,-PROJ---,FILENAME----,USER--,DATE-----,TIME---,STATUS|' -e 's|/Proj/abc/||g' -e 's|/conf||g' -e 's|/|,|2' -e 's|/|,|1' file
Just an extended set of stream replacements.
The first changes the first line to starting with the string beginning with LB
that you want.
The second removes /Proj/abc/.
The third removes /conf.
The fourth and fifth replace the 2nd and 1st forward slashes with commas.
Output:
LB,-PROJ---,FILENAME----,USER--,DATE-----,TIME---,STATUS
app,app_pit,HUB_TEST.apx,uJones,4/24/2018,5:55:58,OK
app,app_pit,test_acqit1.apx,uSmith,3/8/2018,10:16:41,OK
app,app_pit,test_bkfs.apx,uHarry,/26/2018,9:47:03,OK
Hello Nasir and thanks for your reply. I notice your solution has still has "PATH and FILENAME" which needs to be divided into LB, PROJ, FILENAME but neither way is printing the header. The data looks great! Any ideas?
â SSDdude
Jun 19 at 14:08
@SSDdude Thesed -e
only sends the changes to std output and it changes "PATH and FILENAME" to LB, PROJ, FILENAME when I do it on my machine with the output as what's above in my answer. If you want the changes to the file, add-i
aftersed
. Are you usinggnu sed
?
â Nasir Riley
Jun 19 at 14:33
add a comment |Â
up vote
1
down vote
sed -e 's|-------------PATH AND FILE NAME--------,USER--,DATE-----,TIME---,STATUS|LB,-PROJ---,FILENAME----,USER--,DATE-----,TIME---,STATUS|' -e 's|/Proj/abc/||g' -e 's|/conf||g' -e 's|/|,|2' -e 's|/|,|1' file
Just an extended set of stream replacements.
The first changes the first line to starting with the string beginning with LB
that you want.
The second removes /Proj/abc/.
The third removes /conf.
The fourth and fifth replace the 2nd and 1st forward slashes with commas.
Output:
LB,-PROJ---,FILENAME----,USER--,DATE-----,TIME---,STATUS
app,app_pit,HUB_TEST.apx,uJones,4/24/2018,5:55:58,OK
app,app_pit,test_acqit1.apx,uSmith,3/8/2018,10:16:41,OK
app,app_pit,test_bkfs.apx,uHarry,/26/2018,9:47:03,OK
Hello Nasir and thanks for your reply. I notice your solution has still has "PATH and FILENAME" which needs to be divided into LB, PROJ, FILENAME but neither way is printing the header. The data looks great! Any ideas?
â SSDdude
Jun 19 at 14:08
@SSDdude Thesed -e
only sends the changes to std output and it changes "PATH and FILENAME" to LB, PROJ, FILENAME when I do it on my machine with the output as what's above in my answer. If you want the changes to the file, add-i
aftersed
. Are you usinggnu sed
?
â Nasir Riley
Jun 19 at 14:33
add a comment |Â
up vote
1
down vote
up vote
1
down vote
sed -e 's|-------------PATH AND FILE NAME--------,USER--,DATE-----,TIME---,STATUS|LB,-PROJ---,FILENAME----,USER--,DATE-----,TIME---,STATUS|' -e 's|/Proj/abc/||g' -e 's|/conf||g' -e 's|/|,|2' -e 's|/|,|1' file
Just an extended set of stream replacements.
The first changes the first line to starting with the string beginning with LB
that you want.
The second removes /Proj/abc/.
The third removes /conf.
The fourth and fifth replace the 2nd and 1st forward slashes with commas.
Output:
LB,-PROJ---,FILENAME----,USER--,DATE-----,TIME---,STATUS
app,app_pit,HUB_TEST.apx,uJones,4/24/2018,5:55:58,OK
app,app_pit,test_acqit1.apx,uSmith,3/8/2018,10:16:41,OK
app,app_pit,test_bkfs.apx,uHarry,/26/2018,9:47:03,OK
sed -e 's|-------------PATH AND FILE NAME--------,USER--,DATE-----,TIME---,STATUS|LB,-PROJ---,FILENAME----,USER--,DATE-----,TIME---,STATUS|' -e 's|/Proj/abc/||g' -e 's|/conf||g' -e 's|/|,|2' -e 's|/|,|1' file
Just an extended set of stream replacements.
The first changes the first line to starting with the string beginning with LB
that you want.
The second removes /Proj/abc/.
The third removes /conf.
The fourth and fifth replace the 2nd and 1st forward slashes with commas.
Output:
LB,-PROJ---,FILENAME----,USER--,DATE-----,TIME---,STATUS
app,app_pit,HUB_TEST.apx,uJones,4/24/2018,5:55:58,OK
app,app_pit,test_acqit1.apx,uSmith,3/8/2018,10:16:41,OK
app,app_pit,test_bkfs.apx,uHarry,/26/2018,9:47:03,OK
answered Jun 14 at 15:58
Nasir Riley
1,504138
1,504138
Hello Nasir and thanks for your reply. I notice your solution has still has "PATH and FILENAME" which needs to be divided into LB, PROJ, FILENAME but neither way is printing the header. The data looks great! Any ideas?
â SSDdude
Jun 19 at 14:08
@SSDdude Thesed -e
only sends the changes to std output and it changes "PATH and FILENAME" to LB, PROJ, FILENAME when I do it on my machine with the output as what's above in my answer. If you want the changes to the file, add-i
aftersed
. Are you usinggnu sed
?
â Nasir Riley
Jun 19 at 14:33
add a comment |Â
Hello Nasir and thanks for your reply. I notice your solution has still has "PATH and FILENAME" which needs to be divided into LB, PROJ, FILENAME but neither way is printing the header. The data looks great! Any ideas?
â SSDdude
Jun 19 at 14:08
@SSDdude Thesed -e
only sends the changes to std output and it changes "PATH and FILENAME" to LB, PROJ, FILENAME when I do it on my machine with the output as what's above in my answer. If you want the changes to the file, add-i
aftersed
. Are you usinggnu sed
?
â Nasir Riley
Jun 19 at 14:33
Hello Nasir and thanks for your reply. I notice your solution has still has "PATH and FILENAME" which needs to be divided into LB, PROJ, FILENAME but neither way is printing the header. The data looks great! Any ideas?
â SSDdude
Jun 19 at 14:08
Hello Nasir and thanks for your reply. I notice your solution has still has "PATH and FILENAME" which needs to be divided into LB, PROJ, FILENAME but neither way is printing the header. The data looks great! Any ideas?
â SSDdude
Jun 19 at 14:08
@SSDdude The
sed -e
only sends the changes to std output and it changes "PATH and FILENAME" to LB, PROJ, FILENAME when I do it on my machine with the output as what's above in my answer. If you want the changes to the file, add -i
after sed
. Are you using gnu sed
?â Nasir Riley
Jun 19 at 14:33
@SSDdude The
sed -e
only sends the changes to std output and it changes "PATH and FILENAME" to LB, PROJ, FILENAME when I do it on my machine with the output as what's above in my answer. If you want the changes to the file, add -i
after sed
. Are you using gnu sed
?â Nasir Riley
Jun 19 at 14:33
add a comment |Â
up vote
0
down vote
Note that this will catch fire if any of the filenames have a ,
or /
in them:
$ awk -F "[/,]" -v OFS="," 'BEGIN print "LB", "-PROJ--", "FILENAME----", "USER--", "DATA-----", "TIME---", "STATUS" NR!=1print $4,$5,$7,$8,$9"/"$10"/"$11,$12,$13' input
LB,-PROJ--,FILENAME----,USER--,DATA-----,TIME---,STATUS
app,app_pit,HUB_TEST.apx,uJones,4/24/2018,5:55:58,OK
app,app_pit,test_acqit1.apx,uSmith,3/8/2018,10:16:41,OK
app,app_pit,test_bkfs.apx,uHarry,/26/2018,9:47:03,OK
add a comment |Â
up vote
0
down vote
Note that this will catch fire if any of the filenames have a ,
or /
in them:
$ awk -F "[/,]" -v OFS="," 'BEGIN print "LB", "-PROJ--", "FILENAME----", "USER--", "DATA-----", "TIME---", "STATUS" NR!=1print $4,$5,$7,$8,$9"/"$10"/"$11,$12,$13' input
LB,-PROJ--,FILENAME----,USER--,DATA-----,TIME---,STATUS
app,app_pit,HUB_TEST.apx,uJones,4/24/2018,5:55:58,OK
app,app_pit,test_acqit1.apx,uSmith,3/8/2018,10:16:41,OK
app,app_pit,test_bkfs.apx,uHarry,/26/2018,9:47:03,OK
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Note that this will catch fire if any of the filenames have a ,
or /
in them:
$ awk -F "[/,]" -v OFS="," 'BEGIN print "LB", "-PROJ--", "FILENAME----", "USER--", "DATA-----", "TIME---", "STATUS" NR!=1print $4,$5,$7,$8,$9"/"$10"/"$11,$12,$13' input
LB,-PROJ--,FILENAME----,USER--,DATA-----,TIME---,STATUS
app,app_pit,HUB_TEST.apx,uJones,4/24/2018,5:55:58,OK
app,app_pit,test_acqit1.apx,uSmith,3/8/2018,10:16:41,OK
app,app_pit,test_bkfs.apx,uHarry,/26/2018,9:47:03,OK
Note that this will catch fire if any of the filenames have a ,
or /
in them:
$ awk -F "[/,]" -v OFS="," 'BEGIN print "LB", "-PROJ--", "FILENAME----", "USER--", "DATA-----", "TIME---", "STATUS" NR!=1print $4,$5,$7,$8,$9"/"$10"/"$11,$12,$13' input
LB,-PROJ--,FILENAME----,USER--,DATA-----,TIME---,STATUS
app,app_pit,HUB_TEST.apx,uJones,4/24/2018,5:55:58,OK
app,app_pit,test_acqit1.apx,uSmith,3/8/2018,10:16:41,OK
app,app_pit,test_bkfs.apx,uHarry,/26/2018,9:47:03,OK
answered Jun 14 at 15:12
DopeGhoti
39.8k54779
39.8k54779
add a comment |Â
add a comment |Â
up vote
0
down vote
Awk
solution:
awk 'BEGIN FS = OFS = ","
NR == 1 $1 = "LB,-PROJ---,FILENAME----"
NR > 1conf)", "", $1);
gsub("/", ",", $1)
1' file
The output:
LB,-PROJ---,FILENAME----,USER--,DATE-----,TIME---,STATUS
app,app_pit,HUB_TEST.apx,uJones,4/24/2018,5:55:58,OK
app,app_pit,test_acqit1.apx,uSmith,3/8/2018,10:16:41,OK
app,app_pit,test_bkfs.apx,uHarry,/26/2018,9:47:03,OK
add a comment |Â
up vote
0
down vote
Awk
solution:
awk 'BEGIN FS = OFS = ","
NR == 1 $1 = "LB,-PROJ---,FILENAME----"
NR > 1conf)", "", $1);
gsub("/", ",", $1)
1' file
The output:
LB,-PROJ---,FILENAME----,USER--,DATE-----,TIME---,STATUS
app,app_pit,HUB_TEST.apx,uJones,4/24/2018,5:55:58,OK
app,app_pit,test_acqit1.apx,uSmith,3/8/2018,10:16:41,OK
app,app_pit,test_bkfs.apx,uHarry,/26/2018,9:47:03,OK
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Awk
solution:
awk 'BEGIN FS = OFS = ","
NR == 1 $1 = "LB,-PROJ---,FILENAME----"
NR > 1conf)", "", $1);
gsub("/", ",", $1)
1' file
The output:
LB,-PROJ---,FILENAME----,USER--,DATE-----,TIME---,STATUS
app,app_pit,HUB_TEST.apx,uJones,4/24/2018,5:55:58,OK
app,app_pit,test_acqit1.apx,uSmith,3/8/2018,10:16:41,OK
app,app_pit,test_bkfs.apx,uHarry,/26/2018,9:47:03,OK
Awk
solution:
awk 'BEGIN FS = OFS = ","
NR == 1 $1 = "LB,-PROJ---,FILENAME----"
NR > 1conf)", "", $1);
gsub("/", ",", $1)
1' file
The output:
LB,-PROJ---,FILENAME----,USER--,DATE-----,TIME---,STATUS
app,app_pit,HUB_TEST.apx,uJones,4/24/2018,5:55:58,OK
app,app_pit,test_acqit1.apx,uSmith,3/8/2018,10:16:41,OK
app,app_pit,test_bkfs.apx,uHarry,/26/2018,9:47:03,OK
answered Jun 14 at 15:21
RomanPerekhrest
22.4k12144
22.4k12144
add a comment |Â
add a comment |Â
up vote
0
down vote
SOLVED!
sed -e 's|-------------PATH AND FILE NAME--------,USER--,DATE-----,TIME---,STATUS|LB,-PROJ---,FILENAME----,USER--,DATE-----,TIME---,STATUS|' -e 's|/Proj/abc/||g' -e 's|/conf||g' -e 's|/|,|2' -e 's|/|,|1' file
Thanks Nasir Riley, your sed solution worked flawlessly!!
The right thing to do here is to accept Nasir's solution (click the checkbox), not repeat their answer.
â Jeff Schaller
Jun 19 at 17:13
add a comment |Â
up vote
0
down vote
SOLVED!
sed -e 's|-------------PATH AND FILE NAME--------,USER--,DATE-----,TIME---,STATUS|LB,-PROJ---,FILENAME----,USER--,DATE-----,TIME---,STATUS|' -e 's|/Proj/abc/||g' -e 's|/conf||g' -e 's|/|,|2' -e 's|/|,|1' file
Thanks Nasir Riley, your sed solution worked flawlessly!!
The right thing to do here is to accept Nasir's solution (click the checkbox), not repeat their answer.
â Jeff Schaller
Jun 19 at 17:13
add a comment |Â
up vote
0
down vote
up vote
0
down vote
SOLVED!
sed -e 's|-------------PATH AND FILE NAME--------,USER--,DATE-----,TIME---,STATUS|LB,-PROJ---,FILENAME----,USER--,DATE-----,TIME---,STATUS|' -e 's|/Proj/abc/||g' -e 's|/conf||g' -e 's|/|,|2' -e 's|/|,|1' file
Thanks Nasir Riley, your sed solution worked flawlessly!!
SOLVED!
sed -e 's|-------------PATH AND FILE NAME--------,USER--,DATE-----,TIME---,STATUS|LB,-PROJ---,FILENAME----,USER--,DATE-----,TIME---,STATUS|' -e 's|/Proj/abc/||g' -e 's|/conf||g' -e 's|/|,|2' -e 's|/|,|1' file
Thanks Nasir Riley, your sed solution worked flawlessly!!
answered Jun 19 at 17:09
SSDdude
544
544
The right thing to do here is to accept Nasir's solution (click the checkbox), not repeat their answer.
â Jeff Schaller
Jun 19 at 17:13
add a comment |Â
The right thing to do here is to accept Nasir's solution (click the checkbox), not repeat their answer.
â Jeff Schaller
Jun 19 at 17:13
The right thing to do here is to accept Nasir's solution (click the checkbox), not repeat their answer.
â Jeff Schaller
Jun 19 at 17:13
The right thing to do here is to accept Nasir's solution (click the checkbox), not repeat their answer.
â Jeff Schaller
Jun 19 at 17:13
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%2f449833%2fparse-linux-paths-as-columns-in-a-csv-file-bash%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
Are
/Proj/abc/
and/conf/
literal constant strings here? or do they vary from record to record?â steeldriver
Jun 14 at 15:12
where does
LB,-PROJ---
come from?â RomanPerekhrest
Jun 14 at 15:14
They appear to be very constant. Thanks!
â SSDdude
Jun 14 at 15:15