Redirecting output from Nth line

Dear All,

I have a shell script which output like some thing below

1.2.3.4
1.2.3.5
1.2.3.6
------
Start of CSV
-------
id ,number ,name ,location
1,101,asp,xyz
2,102,dsp,ert

Now i need to redirect this output to csv file but from particular line number. i mean, first i need to skip first 3 lines , redirect rest to csv output

$> du.sh >  log.csv 

Where I need to skip first 3 lines which

1.2.3.4
1.2.3.5
1.2.3.6

but only redirect from line 4..

can you please guide me

Please use code tags.

tail:

du.sh | tail -n +4

sed:

du.sh | sed '1,3d'

awk:

du.sh | awk 'NR>3'

There may be others.

Andrew

1 Like

Hi andrew,

Sed works..thank you but I need one more suggestion

I am getting extra , (comma) at end of line, so i need to remove it.. so trying below, but it saying syntax error line 2. at > /home/centos/abc.csv

#!/bin/bash
sh /home/centos/du.sh | sed 1,124d > /home/centos/abc.csv
for fname in abc.csv
   do
   cat $fname | sed 's/.$//' > tmp.tmp
   mv tmp.tmp $fname
done

------ Post updated at 07:24 AM ------

its working now... used , instead of . in sed

A bit overcomplicated, no? A for loop for a single file, two sed invocations in lieu of one. . . Why not (untested)

sh /home/centos/du.sh | sed '1,124d; s/.$//' > /home/centos/abc.csv
1 Like

This works too :slight_smile:

Or simply invert the sed printing to have one command:

sh /home/centos/du.sh | sed -n '125,$ s/,$//p'

Andrew

1 Like