I have a csv file looks like this:




is it possible manipulate above csv file and export as follows: (using sed or awk or similar bash commands)




Actually i want to manipulate only 4th column and Remain http://foo.com/{some string} pattern (in other words, extract links from 4th column when contain foo.com domain)

  • 1
    Do the \n mean 'newline' ? – Costas Oct 30 '16 at 9:07
  • yes \n mean 'newline'.but Is ineffective in csv file. – alrz Oct 31 '16 at 6:42
  • It is matter whether each http on separate line or not. What output produce cat file.csv ? – Costas Nov 1 '16 at 17:02
sed '
    s|http://foo.com|@|g #replace `foo.com` domain with rare symbol
    /./s/\\n\|$/;/g      #replace `\n` by `;`  and add it to end 
    s/http[^@]*;//g      #remove all domain(s) without `foo.com`
    s|@|http://foo.com|g #place `foo.com` back
    s/;$//               #remove `;` from the end of line
    ' csv.file

You can do the following:

cat your_csv.csv | sed 's/\\n/,/g' | cut -d ',' -f 4

sed will change all the \ns to , and cut chooses the 4th field when the delimiter is ,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.