Sponsored Content
Full Discussion: How to echo "#" to files?
Top Forums Shell Programming and Scripting How to echo "#" to files? Post 302864455 by Yongfeng on Wednesday 16th of October 2013 02:22:10 PM
Old 10-16-2013
Hi, I also tested it today and it works fine. But here I actually want to make it automatic, which means once take a file, we can go through each line of it, extract the line and echo it to another file. Here's the code:

Code:
 i=bin.sh
           echo "#!/bin/bash" > bundle.sh  
           number=`wc -l < $i`  #count the number of lines
           count=1
           while [ $count -le $number ]
           do
                 tmp=`sed -n "$count,1p" $i`   #extract the $count-th line
                 echo "echo $tmp" >> $i" >> bundle.sh
                 count=$(($count+1))
done

As you can see, the above code generates commands that will recreate file bin.sh, and exports these commands to another script called bundle.sh. So when bundle.sh is run, bin.sh is supposed to be generated. but if we encountered some special characters such as # and ; in bin.sh (the file to be recreated somewhere else), the second echo in echo "echo $tmp >> $i" >> bundle.sh won't be able to pass $tmp to $i because this command outputs: echo #contents or contents; >> bin.sh, codes after # will be interpreted as comments and ; will be interpreted as end of the line. Haven't found a way to figure it out yet. Many thanks.

Last edited by Yongfeng; 10-16-2013 at 03:28 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

"sed" to check file size & echo " " to destination file

Hi, I've modified the syslogd source to include a thread that will keep track of a timer(or a timer thread). My intention is to check the file size of /var/log/messages in every one minute & if the size is more than 128KB, do a echo " " > /var/log/messages, so that the file size will be set... (7 Replies)
Discussion started by: jockey007
7 Replies

2. Shell Programming and Scripting

Difference between using "echo" builtin and /bin/echo

So in my shell i execute: { while true; do echo string; sleep 1; done } | read line This waits one second and returns. But { while true; do /bin/echo string; sleep 1; done } | read line continues to run, and doesn't stop until i kill it explicitly. I have tried this in bash as well as zsh,... (2 Replies)
Discussion started by: ulidtko
2 Replies

3. Shell Programming and Scripting

Delete files older than "x" if directory size is greater than "y"

I wrote a script to delete files which are older than "x" days, if the size of the directory is greater than "y" #!/bin/bash du -hs $1 while read SIZE ENTRY do if ; then find $1 -mtime +$2 -exec rm -f {} \; echo "Files older than $2 days deleted" else echo "free Space available"... (4 Replies)
Discussion started by: JamesCarter
4 Replies

4. Shell Programming and Scripting

"Join" or "Merge" more than 2 files into single output based on common key (column)

Hi All, I have working (Perl) code to combine 2 input files into a single output file using the join function that works to a point, but has the following limitations: 1. I am restrained to 2 input files only. 2. Only the "matched" fields are written out to the "matched" output file and... (1 Reply)
Discussion started by: Katabatic
1 Replies

5. Shell Programming and Scripting

With that logic this echoes "echo". Question about echo!

echo `echo ` doesn't echoes anything. And it's logic. But echo `echo `echo ` ` does echoes "echo". What's the logic of it? the `echo `echo ` inside of the whole (first) echo, echoes nothing, so the first echo have to echo nothing but echoes "echo" (too much echoing :P):o (2 Replies)
Discussion started by: hakermania
2 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. AIX

echo $varibla | mail -s "subject" "xxx@xxx.com" not ruuning as expected

Hi Folks, As per the subject, the following command is not working as expected. echo $variable | mail -s "subject" "xxx@xxx.com" Could anyone figure it out whats wrong with this. I am using AIX box. Regards, (2 Replies)
Discussion started by: gjarms
2 Replies

8. Shell Programming and Scripting

tcsh - understanding difference between "echo string" and "echo string > /dev/stdout"

I came across and unexpected behavior with redirections in tcsh. I know, csh is not best for redirections, but I'd like to understand what is happening here. I have following script (called out_to_streams.csh): #!/bin/tcsh -f echo Redirected to STDOUT > /dev/stdout echo Redirected to... (2 Replies)
Discussion started by: marcink
2 Replies

9. Shell Programming and Scripting

Delete all log files older than 10 day and whose first string of the first line is "MSH" or "<?xml"

Dear Ladies & Gents, I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out: for filename in $(find /var/log/test... (2 Replies)
Discussion started by: Hiroshi
2 Replies

10. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies
BPING(1)							  BP executables							  BPING(1)

NAME
bping - Send and receive Bundle Protocol echo bundles. SYNOPSIS
bping [-c count] [-i interval] [-p priority] [-q wait] [-r flags] [-t ttl] srcEID destEID [reporttoEID] DESCRIPTION
bping sends bundles from srcEID to destEID. If the destEID echoes the bundles back (for instance, it is a bpecho endpoint), bping will print the round-trip time. When complete, bping will print statistics before exiting. It is very similar to ping, except it works with the bundle protocol. bping terminates when one of the following happens: it receives the SIGINT signal (Ctrl+C), it receives responses to all of the bundles it sent, or it has sent all count of its bundles and waited wait seconds. EXIT STATUS
These exit statuses are taken from ping. 0 bping has terminated normally, and received responses to all the packets it sent. 1 bping has terminated normally, but it did not receive responses to all the packets it sent. 2 bping has terminated due to an error. Details should be noted in the ion.log log file. FILES
No configuration files are needed. ENVIRONMENT
No environment variables apply. DIAGNOSTICS
Diagnostic messages produced by bping are written to the ION log file ion.log and printed to standard error. Diagnostic messages that don't cause bping to terminate indicate a failure parsing an echo response bundle. This means that destEID isn't an echo endpoint: it's responding with some other bundle message of an unexpected format. Can't attach to BP. bpadmin has not yet initialized Bundle Protocol operations. Can't open own endpoint. Another application has already opened ownEndpointId. Terminate that application and rerun. bping bundle reception failed. BP system error. Check for earlier diagnostic messages describing the cause of the error; correct problem and rerun. No space for ZCO extent. ION system error. Check for earlier diagnostic messages describing the cause of the error; correct problem and rerun. Can't create ZCO. ION system error. Check for earlier diagnostic messages describing the cause of the error; correct problem and rerun. bping can't send echo bundle. BP system error. Check for earlier diagnostic messages describing the cause of the error; correct problem and rerun. BUGS
Report bugs to <ion-bugs@korgano.eecs.ohiou.edu> SEE ALSO
bpecho(1), bptrace(1), bpadmin(1), bp(3), ping(8) perl v5.14.2 2012-05-25 BPING(1)
All times are GMT -4. The time now is 12:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy