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
BUNDLE(1)																 BUNDLE(1)

NAME
bundle - Ruby Dependency Management SYNOPSIS
bundle COMMAND [--no-color] [--verbose] [ARGS] DESCRIPTION
Bundler manages an application's dependencies through its entire life across many machines systematically and repeatably. See the bundler website http://gembundler.com for information on getting started, and Gemfile(5) for more information on the Gemfile for- mat. OPTIONS
--no-color Prints all output without color --verbose Prints out additional logging information BUNDLE COMMANDS
We divide bundle subcommands into primary commands and utilities. PRIMARY COMMANDS
bundle install(1) bundle-install.1.html Install the gems specified by the Gemfile or Gemfile.lock bundle update(1) bundle-update.1.html Update dependencies to their latest versions bundle package(1) bundle-package.1.html Package the .gem files required by your application into the vendor/cache directory bundle exec(1) bundle-exec.1.html Execute a script in the context of the current bundle bundle config(1) bundle-config.1.html Specify and read configuration options for bundler bundle help(1) Displays this help page UTILITIES
bundle check(1) Determine whether the requirements for your application are installed and available to bundler bundle list(1) Show all of the gems in the current bundle bundle show(1) Show the source location of a particular gem in the bundle bundle outdated(1) Show all of the outdated gems in the current bundle bundle console(1) Start an IRB session in the context of the current bundle bundle open(1) Open an installed gem in the editor bundle viz(1) Generate a visual representation of your dependencies bundle init(1) Generate a simple Gemfile, placed in the current directory bundle gem(1) Create a simple gem, suitable for development with bundler bundle platform(1) bundle-platform.1.html Displays platform compatibility information bundle clean(1) Cleans up unused gems in your bundler directory OBSOLETE
These commands are obsolete and should no longer be used o bundle lock(1) o bundle unlock(1) o bundle cache(1) March 2013 BUNDLE(1)
All times are GMT -4. The time now is 06:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy