Visit Our UNIX and Linux User Community


Inserting a line at the end


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Inserting a line at the end
# 1  
Old 07-28-2009
Inserting a line at the end

Hi All,

I am using the below script to enter the URL at the end of file:

echo "Enter the URL that should point to the particular microsite"
read url
sed "$a $url" redirects.virgin-atlantic.com.conf > temp

But am getting the below error:

./script.sh[6]: [0: not found
Unrecognized command: Redirect permanent /kpmgxy http://www.virgin-atlantic.com/corpo...w.do?id=305847


Please can you advise.

Best Regards,
Shazin
# 2  
Old 07-28-2009
What is $a here? I am bit confused with your requirement.

If you just want to read and append a line to the end of a file, then try this.

Code:
 
echo "Enter the URL that should point to the particular microsite"
read url
echo $url >>filename

# 3  
Old 07-28-2009
It's because $a is interpreted by the shell. You could use
Code:
sed '$a '$url redirects.virgin-atlantic.com.conf > temp

or much simpler
Code:
echo $url >> redirects.virgin-atlantic.com.conf

# 4  
Old 07-28-2009
Hi,

Still getting the below error:

Enter the URL that should point to the particular microsite
Redirect permanent /kpmgxy http://www.virgin-atlantic.com/corpo...w.do?id=305847
./script.sh[6]: [0: not found
sed: command garbled: $a Redirect
Redirects Setup

Best Regards,
Shazin
# 5  
Old 07-28-2009
Hi,

There's something I don't understand.
is
redirects.virgin-atlantic.com.confthe name of the file? In this case, what is the use of
> temp?

Another question : this script is written for csh shell or ksh. How can I convert this for bash shell? All the Tuto i find use different syntaxes and don't works for bash shell...

If you have little time to explain me or a link to a good website, it'll be really appreciable.

Thanks
# 6  
Old 07-28-2009
Are you sure you want to use "sed"?
Because, the syntax is wrong?

Or are you trying to use "cat"?
As per your requirement you must be using cat.
# 7  
Old 07-28-2009
Rule 10: [...]Don't send a private message with a technical question. The forums are for the benefit of all, so all Q&A should take place in the forums.
Also, please learn how to enclose your code in appropriate tags. It's the '#' symbol above the posting box.

Quote:
Originally Posted by Shazin
Hi

I am using the below script to enter a line in the file:

Code:
#!/bin/ksh
# To delete the last line if it contains the pattern Redirect permanent / http://www.virgin-atlantic.com
echo "Enter the URL that should point to the particular microsite"
read url
# To delete the last line if it contains the pattern Redirect permanent / http://www.virgin-atlantic.com
grep "Redirect permanent / http://www.virgin-atlantic.com" redirects.virgin-atlantic.com.conf > output1
if [$? -eq 0] ; then
    rm -r output1
    sed '$d' redirects.virgin-atlantic.com.conf > temp
    #cp temp redirects.virgin-atlantic.com.conf
    echo $url >> temp
    echo "Redirect permanent / http://www.virgin-atlantic.com" >> temp
    echo "Redirects Setup"
else
    echo $url >> temp
    echo "Redirects Setup"
fi

and am getting the error below:

Enter the URL that should point to the particular microsite
Redirect permanent /kpmgxy Virgin Atlantic Airways - Popup
./script.sh[7]: [0: not found
Redirects Setup

Please can you advise.

Best Regards,
Shazin
If you'd have posted the whole part before, not just the part where you thought the error was, we could have told you that the testing expression for the if requires whitespace surrounding the brackets, eg
Code:
if [ $? -eq 0 ]; then


Previous Thread | Next Thread
Test Your Knowledge in Computers #895
Difficulty: Medium
The GNU Core Utilities or coreutils is a package of GNU software containing reimplementations for many of the basic tools, such as cat, ls, and rm, which are used on Unix-like operating systems.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Inserting a blank line at the end of a .txt file?

Hi there, I am having this problem: a) I am uploading a txt file from windows (notepad) with some Gaussian 09 command lines; b) Gaussian needs in certain command files, that those files have a blank line at the end of the file! c) I open the command file with vi and no blank line at the of... (2 Replies)
Discussion started by: luismga
2 Replies

2. UNIX for Dummies Questions & Answers

Inserting new line

Hi all, I want ot print a header with new line in the end. I am using echo like echo "this is header" I want output like This is header $ I tried -e also but it's not working. echo - e Can anyone help please? (6 Replies)
Discussion started by: dsa
6 Replies

3. Shell Programming and Scripting

Inserting semicolon at the end of a line

HI Am totally confused with sed and translate command command.. My problem is I have a file like # vi test.csv ABC_IMUY ERD0_FN VEG_NON_DES_IYT BUY4_FLOW POI_SHD_URDF_IYUT_REDS_CYC UYT_PMC4_WIND EX_FRE_FRD_L2_REF_FLICT JHY_SGT_DSE_L2 IYO_HYTR_FGT_L3_BGT_ICT... (5 Replies)
Discussion started by: Priya Amaresh
5 Replies

4. Shell Programming and Scripting

Commenting a specific line and inserting a new line after commented line.

Hello All, I have following file contents cat file #line=aaaaaa #line=bbbbbb #line=cccccc #line=dddddd line=eeeeee #comment=11111 #comment=22222 #comment=33333 #comment=44444 comment=55555 Testing script Good Luck! I would like to comment line line=eeeeee and insert a new line... (19 Replies)
Discussion started by: manishdivs
19 Replies

5. Shell Programming and Scripting

Help with inserting a line

Hello, I am new to this forum. I have a question in Unix shell scripting. Here is my requirement I have 1000 files and I need to insert a header with one line at the top of each of the 1000 files. Please let me know if you have any solution for this Thanks in advance. Raj (4 Replies)
Discussion started by: trajashekar
4 Replies

6. Shell Programming and Scripting

Inserting a line in a file after every alternate line

Friends , I have a large file and i need to insert a line after every line.I am actually unaware how to do it.Any help appreciated. My File control station *ATM* , qread $OSS.Jul13A.FI01 interval 1 intcount 1 control station *ATM* , qread $OSS.Jul13A.FI02 interval 1 intcount... (4 Replies)
Discussion started by: appu2176
4 Replies

7. UNIX for Dummies Questions & Answers

Inserting a ' at the end of each line

Hi all, I can use the following command to insert a ' at the beginning of each line sed "s/^/'/g" test.txt > test1.txt However, I'm unable to use the following to insert a ' at the end of each line in this way sed "s/$/'/g" test.txt > test1.txt Any... (3 Replies)
Discussion started by: karthiknaidu
3 Replies

8. UNIX for Dummies Questions & Answers

Inserting control characters at the end of each line

How to add control characters at the end of each line in a file? Can anyone help me with this? Thanks, Shobana (2 Replies)
Discussion started by: Shobana_s
2 Replies

9. UNIX for Advanced & Expert Users

Inserting a line before the line which matches the patter

Hi Is there any command where we can insert a line "2|||" before every line starting with "3|" my input is as follows 1|ETG|12345 3|79.58|||GBP|| 1|ETG|12345 3|79.58|||GBP|| 1|ETG|12345 2|EN_GB||Electrogalvanize 0.5 m2 ( Renault ) 1|ETG|12345 3|88.51|||GBP|| desired output... (10 Replies)
Discussion started by: laxmi131
10 Replies

10. Shell Programming and Scripting

Inserting a new line

I have a file where each line starts with a "update" statement. I want to insert a new line, after each line, with the words "go" in the new line. Can someone help me out with this? (1 Reply)
Discussion started by: ssmallya
1 Replies

Featured Tech Videos