TRAILER!! Output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting TRAILER!! Output
# 1  
Old 04-06-2006
TRAILER!! Output

I run my script which i wrote which has the job of inputing a line of text into a certain place in a file. When i run the script i get an error which relates to one line of code as shown below:

sed -n '$count p' $2 | cpio -o >> tempfile

The error i keep getting from this line is this:

sed: -e expression #1, char 3: Extra characters after command
1 block
sed: -e expression #1, char 3: Extra characters after command
1 block

and so on as long as it loops. Anyway i don't know why this is happenning and the file that i am inputing into tempfile contains a brunch of stuff that looks like this:

^@^@^@^@^@^@Çq^@^@^@^@^@^@^@^@^@^@^A^@^@^@^@^@^@^@^K^@^@^@^@^@TRAILER!!!^@^@^@^@^@^@^@^@^@^@^@^@^@^@ ^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ ^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ ^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ ^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ ^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ ^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ ^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ ^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ ^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ ^@^@^@^@^@^@^@^@^@^@^@^@Çq^@^@^@^@^@^@^@^@^@^@^A^@^@^@^@^@^@^@^K^@^@^@^@^@TRAILER!!!^@



Why is this being output to the file and is their anyway to fix my orignal problem?
# 2  
Old 04-06-2006
use double-quotes
# 3  
Old 04-06-2006
That looks a little like untranslated EBCDIC text. Anyway, instead of sed which doesn't seem to like the data, try dd which is meant for playing with stuff like this.
dd will replace cpio and sed. dd will also translate EBCDIC to ASCII if you want.

man dd
# 4  
Old 04-06-2006
sed

I had it in double qoutes but in despair took them off. Cheers on the dd I'll have a look at it and see if it helps.

Last edited by Quesa; 04-06-2006 at 12:08 PM..
# 5  
Old 04-06-2006
I've looked at dd and I don't know if it will work with what I am trying to do. From what i gather dd seems very good at copying with control on blocks. But i need to input a line in a particlar place in a file. The place is to do with line number. So i have loop like so:

while [ "$linenum" -gt 0 ]
do
sed -n ' "$count" p ' $2 | cpio -o >> tempfile

if [ "$linenum" -eq "$reqline" ]
then
echo $1 >> tempfile
fi
reqline=<various calc's>
count=`expr "$count" + 1`
linenum=`expr "$linenum" - 1`
done

I don't think dd will work in this context (I may be wrong ) as it won't let me specfic the line number. It will only let me skip a number of blocks and do things like that. Anyway my knowledge of dd is not complete so I may be wrong.
# 6  
Old 04-06-2006
once again - use double-quotes:
Code:
sed -n "${count}p" myFile

# 7  
Old 04-06-2006
You where right it works when I use the line :
sed -n "$count p" $2 >> tempfile

but not when i use:
sed -n '$count p' $2 >> tempfile


Yet at the command promt if I use say somthing like
sed -n '3 p' $2 >> tempfile
it works fine. Anyway thanks Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Header and trailer Check in UNIX

I am planning to automate multiple files through Unix script. Could you please guide for making the automation for multiple files ? Eg. I have to check header and footer for all files in the particular path and the header pattern should match with the filename. Filename- Filename.txt... (2 Replies)
Discussion started by: karthick2020333
2 Replies

2. Shell Programming and Scripting

Sort without Header and Trailer

Hi , My UNIX system is SUN Solaris. I am trying to do a simple thing as described below. I have a PIPE delimited file that has header and trailer. So the file is something like below: Test1.txt looks like something below: field_data1|field_data2|and some more data --Header ... (5 Replies)
Discussion started by: Saanvi1
5 Replies

3. Shell Programming and Scripting

Identify Trailer record

Hello, My script has a trailer record(TR). Now I need to implement a logic, if TR is missed on the file it should generate me an email stating TR was not on the file.. Kindly help. (15 Replies)
Discussion started by: Harimalyala
15 Replies

4. Shell Programming and Scripting

Verify the header and trailer in file

please see my requirement, I hope I am clear. (9 Replies)
Discussion started by: mirwasim
9 Replies

5. UNIX for Dummies Questions & Answers

Adding header and trailer into a file

Hi, I want to add the below Header to all the files in sequence File1,File2,File3...etc "ABC,<number of chracter in the file>" e,g - If File1 is as below pqrstuvdt abcdefgh then I want to add the above header into it ,So that File1 becomes as below ABC,17 pqrstuvdt abcdefgh ... (9 Replies)
Discussion started by: spari2
9 Replies

6. Solaris

How to test the existence of trailer record

SunOS 5.10 Generic_142900-15 sun4v sparc SUNW,T5240 I have a script that needs to test a file for the existence of a trailer record. Is there a command and is a header and trailer differect record type? Thanks in advance (1 Reply)
Discussion started by: Harleyrci
1 Replies

7. Shell Programming and Scripting

Inserting a trailer

I am new to unix... cn u plz tel me how to add a trailer as a last record of each file. (3 Replies)
Discussion started by: amitpta
3 Replies

8. Shell Programming and Scripting

Header as is.. trailer count

i have .DAT file FILE1.DAT 1200910270040625 2123456789 J123456 ABC 2123456789 K123456 ABC 2222222222 L123456 DEF 2333333333 M12345 GHI 30000004 My outfile FILE2.TXT should have like this, I need the header value as ie (1200910270040625 ) body rows remove the duplicate rows and the... (2 Replies)
Discussion started by: kshuser
2 Replies

9. UNIX for Dummies Questions & Answers

Append Header and Trailer

Hi everyone, I am new to Unix programming. My inquries is:- a) How to add a Header and Trailer in the set of data b) Include a number count of the data in the trailer The set of data only contained the information of 'Customer's Name' and 'Account Number'. I would like to add the Header... (2 Replies)
Discussion started by: balzzz
2 Replies

10. UNIX for Dummies Questions & Answers

Removing trailer from a flat file!!!

Hi, I get some flat files with trailer which gives the totol records count and i want to remove the trailer from the file. i used the following command it works fine with a single file. cat file_name | grep -v 'Total records:' > file1 mv file file_name But i dont know how to remove the... (12 Replies)
Discussion started by: kumarsaravana_s
12 Replies
Login or Register to Ask a Question