Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Linux and Unix
Tag Cloud
access acer asus bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop malware memory monitor motherboard network printer problem ram registry router security slow software sound toshiba trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless xbox
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
How to skip 1st with sed

Reply  
Thread Tools
surfnschultz's Avatar
Member with 191 posts.
 
Join Date: Nov 2003
04-Mar-2005, 05:38 PM #1
How to skip 1st with sed
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's Avatar
Senior Member with 1,335 posts.
 
Join Date: Feb 2005
Experience: Advanced
04-Mar-2005, 06:28 PM #2
Quote:
Originally Posted by surfnschultz
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
Code:
sed 2~1s/pattern1/pattern2/ file.txt
The 2 means start at line 2. The ~ means step by the next value.
surfnschultz's Avatar
Member with 191 posts.
 
Join Date: Nov 2003
04-Mar-2005, 06:48 PM #3
So cool let me try, thanks headrush!!
surfnschultz's Avatar
Member with 191 posts.
 
Join Date: Nov 2003
04-Mar-2005, 06:54 PM #4
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's Avatar
Senior Member with 1,335 posts.
 
Join Date: Feb 2005
Experience: Advanced
04-Mar-2005, 07:05 PM #5
Quote:
Originally Posted by surfnschultz
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?
What is the exact syntax you are using? (command in a script or inline to sed)
surfnschultz's Avatar
Member with 191 posts.
 
Join Date: Nov 2003
04-Mar-2005, 07:10 PM #6
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's Avatar
Member with 191 posts.
 
Join Date: Nov 2003
04-Mar-2005, 07:14 PM #7
I can manipulte the data with vi, but would prefer to do it once with a script
Headrush's Avatar
Senior Member with 1,335 posts.
 
Join Date: Feb 2005
Experience: Advanced
04-Mar-2005, 07:25 PM #8
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's Avatar
Trusted Advisor with 18,706 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
04-Mar-2005, 11:49 PM #9
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.
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 08:05 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.