# How to skip 1st with sed



## surfnschultz (Nov 17, 2003)

I have a file I want to modify every line in this file except the frist line in the file?
sed s/$/whatever 
how would I skip the fisrt line and do this command on the rest of the file?


----------



## Headrush (Feb 9, 2005)

surfnschultz said:


> I have a file I want to modify every line in this file except the frist line in the file?
> sed s/$/whatever
> how would I skip the fisrt line and do this command on the rest of the file?


Try this

```
sed 2~1s/[COLOR=Green]pattern1[/COLOR]/[COLOR=Green]pattern2[/COLOR]/ file.txt
```
The 2 means start at line 2. The ~ means step by the next value.


----------



## surfnschultz (Nov 17, 2003)

So cool let me try, thanks headrush!!


----------



## surfnschultz (Nov 17, 2003)

ok headrush one more question

Since I am using control M as a character I cannot type that. So I have a file with this in it

s/run "ds03853^M1^M//

I want to remove the run part of a 390 line file. I only need the unr onme the first line. When I added the 2~1 in front it failed to run. any clues how to do it int he script file?


----------



## Headrush (Feb 9, 2005)

surfnschultz said:


> ok headrush one more question
> 
> Since I am using control M as a character I cannot type that. So I have a file with this in it
> 
> ...


What is the exact syntax you are using? (command in a script or inline to sed)


----------



## surfnschultz (Nov 17, 2003)

so I am doing this

at the prompt I am type sed -f invloc data > dataout

invloc looks like:
s/run "ds03853^M1^M//

data looks like

run ds03853^M1^M982109^M982109^M3^MY^M

there are 390 lines ilke this in data and I want the first line to stay untouched. and the rest to eliminate the run part.


----------



## surfnschultz (Nov 17, 2003)

I can manipulte the data with vi, but would prefer to do it once with a script


----------



## Headrush (Feb 9, 2005)

I'm a little confused.
Would you please post a paragraph or so of your input file and bold the part you want to search for and remove.

I know after the 1 line, but confused about the length and content after the run.


----------



## Squashman (Apr 4, 2003)

Seems like it would be easier to just remove them all and then run another sed statement to put the run back into the first line. I am pretty sure you can have sed stop after the first match so it would just put the run back on the first line. In fact I am pretty sure you can tell sed what line you want to edit so you could just specify line 1 in the sed script.


----------

