Add line under line help plse


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Add line under line help plse
# 1  
Old 12-18-2007
Add line under line help plse

Hello everyone, i hope someone can help me, i am a complete noob at bash so plse be gentle,
What i want to do is add a line under a line in a file, the file is xorg.conf and the line i would like to add is Option "SHMConfig" "on" under the line Option "Emulate3Buttons" "yes"
what i have found is below but i dont know how to add the params line to find and add and file to edit
Quote:
#!/bin/sh
#usage
if test $# -lt 3; then
echo Usage $0 line_find line_add file1 file2 ...
exit 1
fi
#main code
echo Adding.. \"$2\" below \"$1\"
line=$1; add=$2
shift 2
for file; do
sed -i "s+$line+$line\n$add+g" $file
done
echo Complete.
Thankyou in advance if anyone can help me
# 2  
Old 12-18-2007
Hope this helps

You can use sed's append option:

sed -i.bak '/Option "Emulate3Buttons" "yes"/a\Option "SHMConfig" "on"' xorg.conf
# 3  
Old 12-18-2007
Replace the sed script inside your bash script with the one given here...

Code:
sed '/Option "Emulate3Buttons" "yes"/a\
Option "SHMConfig" "on"
' $file

# 4  
Old 12-18-2007
Thank you so much, just what i wanted
# 5  
Old 12-18-2007
I almost have it thank you so much i am much closer, the problem is that it wont write the line, if i put it to write under a normal line ie without the spaces etc it works but not for the line i want, i have double checked spelling etc even copied paste the line etc, i think the spacings or something is messing it up, hope i have explained it right.
# 6  
Old 12-18-2007
solved it after a bit of trial and error it was just spacing, thank you,thank you,thank you,thank you,thank you,thank you,thank you,thank you,thank you,thank you,thank you,thank you,thank you,thank you,thank you,thank you,thank you,thank you,
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies

2. Shell Programming and Scripting

Sed/grep: check if line exists, if not add line?

Hello, I'm trying to figure out how to speed up the following as I want to use multiple commands to search thousands of files. is there a way to speed things up? Example I want to search a bunch of files for a specific line, if this line already exists do nothing, if it doesn't exist add it... (4 Replies)
Discussion started by: f77hack
4 Replies

3. Shell Programming and Scripting

How to add the line to previous line in | delimited text?

Hi All, I am new to Unix and I have one challenge and below are the details. I have pipe delimited text file in that data has span into multiple lines instead of single line. Sample data. Data should be like below for entire file. 41|216|398555|77|provided complete NP outcome data ... (21 Replies)
Discussion started by: Narasimhasss
21 Replies

4. Shell Programming and Scripting

how to read the contents of two files line by line and compare the line by line?

Hi All, I'm trying to figure out which are the trusted-ips and which are not using a script file.. I have a file named 'ip-list.txt' which contains some ip addresses and another file named 'trusted-ip-list.txt' which also contains some ip addresses. I want to read a line from... (4 Replies)
Discussion started by: mjavalkar
4 Replies

5. Shell Programming and Scripting

Add line break for each line in a file

I cannot seem to get this to work.. I have a file which has about 100 lines, and there is no end of line (line break \n) at the end of each line, and this is causing problem when i paste them into an application. the file looks like this this is a test that is a test balblblablblhblbha... (1 Reply)
Discussion started by: fedora
1 Replies

6. Shell Programming and Scripting

add number in lines line by line in different files

I have a set of log files that are in the following format ======= set_1 ======== counter : 315 counter2: 204597 counter3: 290582 ======= set_2 ======== counter : 315 counter2: 204597 counter3: 290582 ======= set_3 ======== counter : 315 counter2: 204597 counter3: 290582 Is... (6 Replies)
Discussion started by: grandguest
6 Replies

7. Shell Programming and Scripting

howto add line as a first line into a non empty file

Hi Trying to do like this : echo "$variable1\n $(cat file.txt)" but it only adds one time. When I run this cmd again with different variable it only replaces line of variable1. How to add constantly line into first line in file ? (3 Replies)
Discussion started by: presul
3 Replies

8. Shell Programming and Scripting

Add new parameters into a line, and redirect the line to other file

How can i add new parameters into a line, and redirect the line to other file? For example: 1.sh name:owner google:richard youtube:student I want a, for example 2.sh with: name:owner:description google:richard:search site youtube:student:video site In the 2.sh, I added a new column:... (7 Replies)
Discussion started by: rafazz
7 Replies

9. Shell Programming and Scripting

Get the 1st 99 characters and add new line feed at the end of the line

I have a file with varying record length in it. I need to reformat this file so that each line will have a length of 100 characters (99 characters + the line feed). AU * A01 EXPENSE 6990370000 CWF SUBC TRAVEL & MISC MY * A02 RESALE 6990788000 Y... (3 Replies)
Discussion started by: udelalv
3 Replies

10. Shell Programming and Scripting

SED help (remove line::parse again::add line)

Aloha! I have just over 1k of users that have permissions that they shouldn't under our system. I need to parse a provided list of usernames, check their permissions file, and strip the permissions that they are not allowed to have. If upon the permissions strip they are left with no permissions,... (6 Replies)
Discussion started by: Malumake
6 Replies
Login or Register to Ask a Question