Put a string to the beginning of a file without a linefeed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Put a string to the beginning of a file without a linefeed
# 1  
Old 09-18-2014
Put a string to the beginning of a file without a linefeed

Hello,

I need to put the following string to the beginning of a file - but it should not create a newline at the end of the string.

So, the file I have is a compressed one - with gzip.

And I would like to add an ASCII-String to the beginning of the file. The string has a length of 69 characters. For example:
Code:
'Xjunuolds 001.9092.12398734.Ght.x PPP.001 '

So, what I need is the following as example:
Code:
Xjunuolds 001.9092.12398734.Ght.x PPP.001 iei´ß)(/&%$jdd...

I tried to do it with a sed - I found with Google, but unfortunately a sed -i ... does not work, because the option -i is not supported...

Do you have any other solution?

Last edited by rbatte1; 09-18-2014 at 10:00 AM.. Reason: Changed ICODE tags to just CODE tags
# 2  
Old 09-18-2014
If you edit the file and insert this, how will the file be unzipped later? gunzip will expect the content in specific locations that it controls and I would not rely on the extracted files. How would you expect gunzip to deal with this extra data?

What's the overall intention? Are you trying to edit the content of one of the zipped files somehow?




Robin
# 3  
Old 09-18-2014
if you can put your string in a file (let's say file1):
Code:
printf "your string" > file1
#or
echo -n "your string" > file1

then you can do:
Code:
cat file1 file2 > file3

does it help?

Moderator's Comments:
Mod Comment Please use code tags next time for your code and data. Thanks

Last edited by vbe; 09-18-2014 at 10:34 AM.. Reason: code tags...
This User Gave Thanks to nackstein For This Post:
# 4  
Old 09-18-2014
Tx for this quick help.

Sometimes a solution is so quite easy.... Smilie

By the way, my intention to do this is to have a header for the delivery protocol - within this header (the ascii string) are infos for the delivery tool (i.e. the recipient). When the recipient will get this file, before the uncompressing he has to delete the header first...

CU,
API
# 5  
Old 09-18-2014
your welcome,
anyway if you need it in a pipe:
Code:
{ printf 'your string single quoted is better' ; cat file2 ; } |  sendmail-or-other-command

enjoy shell scripting Smilie

Moderator's Comments:
Mod Comment Please use code tags next time for your code and data. Thanks

Last edited by vbe; 09-18-2014 at 11:06 AM.. Reason: code tags please
This User Gave Thanks to nackstein For This Post:
# 6  
Old 09-18-2014
Tx a lot. Thats exactly what I need...

That was a really good work... SmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

remove all occurrences of a character at the beginning of a string

Hi there, i need some help to remove all occurrences of a certain character at the beginning of a string. Example: my string is 00102030 and i want to remove all zeros from beginning of string so the result is 102030 (3 Replies)
Discussion started by: gigagigosu
3 Replies

2. Shell Programming and Scripting

Use grep sed or awk to extract string from log file and put into CSV

I'd like to copy strings from a log file and put them into a CSV. The strings could be on different line numbers, depending on size of log. Example Log File: File = foo.bat Date = 11/11/11 User = Foo Bar Size = 1024 ... CSV should look like: "foo.bat","11/11/11","Foo Bar","1024" (7 Replies)
Discussion started by: chipperuga
7 Replies

3. Shell Programming and Scripting

How to remove white spaces from the beginning an end of a string in unix?

Suppose, I have a variable var=" name is ". I want to remove the blank spaces from the begining and endonly, not from the entire string. So, that the variable/string looks like following var="name is". Please look after the issue. (3 Replies)
Discussion started by: mady135
3 Replies

4. Shell Programming and Scripting

How to compare particular string, if it is equal put into a new file

Hi, I have a file (sample.txt) this file contains below text. ./au ./11.5.0 ./11.5.0/admin ./11.5.0/admin/driver ./po ./11.5.0 ./11.5.0/admin ./11.5.0/admin/driver ./xxsbx/11.5.0/java/src ./xxsbx/11.5.0/lib ./xxsel ./xxsel/11.5.0 ./xxsel/11.5.0/admin ./zfa ./zfa/11.5.0... (2 Replies)
Discussion started by: gagan4599
2 Replies

5. Shell Programming and Scripting

Remove spaces in the beginning of a string

Hi, I am trying to remove spaces from the beginning of a string (which i am using in my shell script). For ex - my string looks like this - " no rows selected" and i want the string to look like this - "no rows selected" How can i achieve this? Thanks! (18 Replies)
Discussion started by: shrutihardas
18 Replies

6. UNIX for Dummies Questions & Answers

Adding one string at the beginning of each line in a file

Hi, I have file a.txt as below. I want to add one string root beginning of each line. Sample file a.txt aaa bbb ccc Sample output Root aaa Root bbb Root ccc Can any one help me on this? (6 Replies)
Discussion started by: siba.s.nayak
6 Replies

7. Shell Programming and Scripting

How to substitute brackets in the beginning of string in perl?

Hi, I have a string like this user can specify different query sets that is why "or" is mentioned: $string="]("; or $string="](("; or $string="]((("; or $string="]((((("; (1 Reply)
Discussion started by: vanitham
1 Replies

8. Shell Programming and Scripting

put a string before a searched string

hi all! i have a working that looks like this... file1 MALE JOHN MALE ANJO FEMALE ANNE MALE JAMES FEMALE HONEY FEMALE IZA what i want to do is insert "M" when the first string is "MALE" and insert "F" when the first string is "FEMALE". file1 M MALE ... (10 Replies)
Discussion started by: kingpeejay
10 Replies

9. UNIX for Dummies Questions & Answers

carriage return and linefeed

hi can anyone please tell me the difference between carriage return, linefeed and newline ? (2 Replies)
Discussion started by: streetfi8er
2 Replies

10. UNIX for Dummies Questions & Answers

linefeed problem

I have a file in which I need to remove all newline characters but only if they are preceded by "^C" ( ASCII value 3 ) Basically this is a bulk copy file with "^B" and "^C" as delimiters for each record. The application producing the file is also appending a newline which I need to remove,... (1 Reply)
Discussion started by: bobgosling
1 Replies
Login or Register to Ask a Question