parse linux paths as columns in a .csv file bash

The name of the pictureThe name of the pictureThe name of the pictureClash 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!







share|improve this question



















  • 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














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!







share|improve this question



















  • 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












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!







share|improve this question











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!









share|improve this question










share|improve this question




share|improve this question









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 does LB,-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










  • 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















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










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






share|improve this answer























  • @steeldriver Ah, the conf has to go too. I will avoid hardcoding app 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

















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





share|improve this answer





















  • 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


















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





share|improve this answer




























    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





    share|improve this answer




























      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!!






      share|improve this answer





















      • 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










      Your Answer







      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "106"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );








       

      draft saved


      draft discarded


















      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






























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






      share|improve this answer























      • @steeldriver Ah, the conf has to go too. I will avoid hardcoding app 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














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






      share|improve this answer























      • @steeldriver Ah, the conf has to go too. I will avoid hardcoding app 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












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






      share|improve this answer















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







      share|improve this answer















      share|improve this answer



      share|improve this answer








      edited Jun 14 at 15:29


























      answered Jun 14 at 15:14









      Kusalananda

      101k13199312




      101k13199312











      • @steeldriver Ah, the conf has to go too. I will avoid hardcoding app 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







      • 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












      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





      share|improve this answer





















      • 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















      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





      share|improve this answer





















      • 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













      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





      share|improve this answer













      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






      share|improve this answer













      share|improve this answer



      share|improve this answer











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

















      • 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
















      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











      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





      share|improve this answer

























        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





        share|improve this answer























          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





          share|improve this answer













          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






          share|improve this answer













          share|improve this answer



          share|improve this answer











          answered Jun 14 at 15:12









          DopeGhoti

          39.8k54779




          39.8k54779




















              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





              share|improve this answer

























                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





                share|improve this answer























                  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





                  share|improve this answer













                  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






                  share|improve this answer













                  share|improve this answer



                  share|improve this answer











                  answered Jun 14 at 15:21









                  RomanPerekhrest

                  22.4k12144




                  22.4k12144




















                      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!!






                      share|improve this answer





















                      • 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














                      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!!






                      share|improve this answer





















                      • 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












                      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!!






                      share|improve this answer













                      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!!







                      share|improve this answer













                      share|improve this answer



                      share|improve this answer











                      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
















                      • 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












                       

                      draft saved


                      draft discarded


























                       


                      draft saved


                      draft discarded














                      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













































































                      Popular posts from this blog

                      How to check contact read email or not when send email to Individual?

                      Bahrain

                      Postfix configuration issue with fips on centos 7; mailgun relay