-1

There is one file in which I am getting data after a pattern -------------- (14 dashes). I want to generate the file in which I will get the text after 14 dashes.

Filename is portals.csv and Text in the file is like:

xyz 
anch 
skjbsejkbkjsbj 
183y83yy3e 
29292.2982 282823 
CSV File begin 
-------------- 
ip,time,release

3 Answers 3

1

Assuming you want everything after the line of dashes, not just one line:

$ sed -E '0,/^-{14}/d' portals.csv 
ip,time,release
some,more,data

0,/-{14}/ matches from the beginning of file (0), to the first line that starts with fourteen dashes. d deletes the matched lines. -E tells sed to use extended regular expressions, the alternative would be /^-\{14\}/. (This would also match lines with more than fourteen dashes, or any trailing garbage after them.)

Using 0 as the start of the range is a GNU extension. With a standard sed, something like this:

< portals.csv sed -nE  -e '/^-{14}/,$p' | sed 1d

(sed -E '1,/^-{14}/d', would fail if the line of dashes is the first line of the file.)

1
  • Awesome, Thanks it worked. You are awesome :) You made my day
    – Syed Rizvi
    Commented Aug 16, 2018 at 11:17
1
perl -0pe 's/^.*-{14}//g' portals.csv  > portals_clean.csv 

Or if you are using whole lines you can use grep

grep -A 1 -P "-{14}" portals.csv  | tail -n 1 > portals_clean.csv 
3
  • Thanks, It's saying command not found. Please correct me, I am executing the command as below: portals.csv perl -0pe 's/^.*-{14}//g' > test.csv -bash: portals.csv: command not found File name is portals.csv and text in file is like: xyz anch skjbsejkbkjsbj 183y83yy3e 29292.2982 282823 CSV File begin -------------- ip,time,release
    – Syed Rizvi
    Commented Aug 16, 2018 at 11:02
  • I included "<" but it didnt worked.
    – Syed Rizvi
    Commented Aug 16, 2018 at 11:13
  • I updated the answer to reflect to your updated question Commented Aug 16, 2018 at 11:20
0

Using sed :

  sed -E -n  '/^-{14}/{n;p;}' file > newfile

Using AWK :

  awk '/^--------------/{p=1;next}p' file > newfile

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .