LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-20-2003, 01:33 PM   #1
niidea
LQ Newbie
 
Registered: Jun 2003
Location: France
Distribution: Slackware 12.1
Posts: 26

Rep: Reputation: 15
sed options


My question is : is there an equivalent for sed to the -v option of gawk ?

I'd like to run the following :
$ sed 'N c\TEXT' FILE
in a shell script to replace the Nth line of FILE by TEXT, where N and TEXT are variables of the script.

Maybe there is another solution ?

Thanks.
 
Old 09-20-2003, 01:54 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Using the correct quotes after the sed command will do the trick:
Code:
#!/bin/bash
#
# infile must be given

INFILE="$1"

# Are input/output file provided:
[[ -z ${INFILE} ]] && echo "No input file given. Quiting" && exit 1

TEXT="This is line number :"

for THIS in 1 2 3 
do
  sed "${THIS}s/.*/${TEXT}${THIS}/" ${INFILE}
  echo ""
done
$ cat inputfile

wertwrtwertwertwertwert
sdfgsfdgsdfgsdfgsdfgsdfg
cvxcvbncvbncbncbncvbncvbn
345634563546356354635636

$ ./sed-options.sh inputfile
This is line number :1
sdfgsfdgsdfgsdfgsdfgsdfg
cvxcvbncvbncbncbncvbncvbn
345634563546356354635636

wertwrtwertwertwertwert
This is line number :2
cvxcvbncvbncbncbncvbncvbn
345634563546356354635636

wertwrtwertwertwertwert
sdfgsfdgsdfgsdfgsdfgsdfg
This is line number :3
345634563546356354635636
$

Last edited by druuna; 09-20-2003 at 01:55 PM.
 
Old 09-20-2003, 02:15 PM   #3
niidea
LQ Newbie
 
Registered: Jun 2003
Location: France
Distribution: Slackware 12.1
Posts: 26

Original Poster
Rep: Reputation: 15
Okay, thanks a lot.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sed ShaqDiesel Programming 8 07-24-2005 06:57 PM
sed and escaping & in something like: echo $y | sed 's/&/_/g' prx Programming 7 02-04-2005 12:00 AM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 07:12 AM
Kernel 2.6.2 options question - LOCKED options ? tvojvodi Linux - General 0 02-17-2004 05:23 AM
sed pk21 Programming 5 09-25-2002 07:03 AM


All times are GMT -5. The time now is 08:45 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration