How to write line1 line2 side by side
Friends,
I am having a text file as below ; line 1 : 123 rama 21 line 2 : dropped INDIA Remarks i want out put as below : line 1 line 2 ie 123 rama 21 dropped INDIA Remarks ( in one line) which command i can use ? Please guide me. Rao |
Quote:
|
Try echo -n line1; echo " " line2 or simply echo line1 line2 if you don't need to write them at different times.
<edit> Here's a script that reads an input file and writes the consecutive lines next to each other: Code:
#!/bin/bash </edit> |
Dear PTrenholme
my file name is "FILE1" and my reuquired output file is "OUTPUTFILE". and my inputfile contains around 1000 lines. Where i have to mention input file and output file names in the shall programme. pl guide RAo |
In the next-to-last line of the script, done < $1, the input to the read is taken from the first argument passed to the script. The output goes to the standard output by default.
So, if you were to take the script I posted and save it to a file, say, for example, "squash" then you would do the following:
Oops! :redface: I was just looking at the code I wrote, and saw that the modulus test ($((${i}%2) should have been 1, not 0. Here's a fancier version of the code with some sanity checks, and changes so you can specify both the input and output file names on the command line. Note that I've only done a few, brief, tests, and cannot warrant that it will satisfy your needs. (I.e., use at your own risk.) Code:
#!/bin/bash |
Dear PTrenholme,
While executing the shell, this following error is coming . My inputfile is FILE!. the error showing is programme name : line 12 : $1 : ambiguous redirect. Pl guide me Thanks Rao |
Please demonstrate how you are calling the script on the command line?
|
Friend grail,
Like below iam writing the awk programme #!/bin/bash i=0 while read do i=$((${i}+1)) if [ $((${i}%2)) -eq 0 ] then hold="${REPLY}" else echo ${hold} ${REPLY} fi done < $1 [ $((${i}%2)) -eq 0 ] && echo ${hold} ===================== the error i showed as above is displaying. Guide me Rao |
Quote:
Also, please use [code][/code] tags when showing code as it is very hard to read all squashed up. So this is the script you are executing. My question is, what are you typing on the command line to run it? |
Um, Rao, if you saved that code as a file, say "prog," then you could run it on two different ways:
I note that you extracted the main loop from the code I provided, thus eliminating the sanity checks and help information. If you had run the code I provided, you should have received an error message and instructions if you failed to provide the correct arguments. (Any "good programming practices" course or book should tell you that you must always assume that users of your code will make mistakes when they do so, and that you should make your code as fool-proof as possible.) P.S.: As grail noted, that is a shell script, not an AWK program. If you wish, I could provide an AWK program to do the same thing, but the shell script is, to me, easier to follow. |
I had a similar problem about a year back and i discovered that variable storage strips out carriage returns.
Code:
echo " Code:
string=$(echo " |
Quote:
Code:
echo "$string" for removing carriage returns. |
Now that is an interesting thing to note. So in this instance I actually wanted to remove the cariage returns, but adding the double quote to the variable allows you to return with the carriage returns.
Code:
string=$(echo " |
All times are GMT -5. The time now is 06:14 PM. |