shell scripting on linux
hi,
I have just started my first experience with shell scripting, i want to write a script to open a text file and in that file copy some lines or repeat some lines in the same file. how do i do that, i mean what is the command to open a text file and edit it ? what is the command for copying lines i tried 'co' command but its not working, which i had seen in one of the tutorials on Google. please help me |
there are many many many commands to do all sorts of things, sed, awk, vi, cat, grep, echo... use whichever you prefer. check out the bash scripting howto as a good starters guide in scripting in general
|
Thanks acid_kewpie . But i want to know if there is any option for repeating a particular line, along with all the other file contents...
please help me |
It depends which tool you use; have a read of these:
http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html |
Quote:
Code:
repeats=5 Rule one in programming: pay attention to the comprehensibility factor -- will you be able to read, understand, and reuse your programs after some time has passed? |
please tell me how to use for loop with sed command is it like this ?
Code:
for((i=1;i<=10;i++)) |
You seem to be asking random questions and it's not clear how they are all related.
Above, you have a nested loop, which looks fine. What happens when you run it? The only thing that I notice is that you need to use double quotes in the sed statement so that the 2 variables will be expanded: Code:
sed -n "$i,$j p" <2K6.rtf > z 1-2 1-3 1-4 .....etc. 2-2 2-3 2-4 .....etc. 3-2 3-3 3-4 ...etc. 4-2 4-3 4-4 ...etc. I hope you can see that some of these do not make sense. All this aside, please post some kind of description of the problem that ties all this together, and then show us the complete code so we can see the whole picture. |
PS: If you have not read the BASH Beginners Guide (link posted by @chrism01), please do so before you try to go too much further.
|
Quote:
Code:
while read -r line |
pixellany, context is for wimps, ok?
|
see ok let me put my doubt in this way i have two files like this
Code:
ATOM 3 C4' G A 1 Code:
ATOM 33 P G A 2 Code:
ATOM 3 C4' G A 1 how do i do this ? |
I hope you can see the problem caused by not giving us the complete problem up front......
You need two nested loops which read from the files, and also keep track of what line numbers are to be read. <<Edit: I found a problem in this---see my post below>> Finally, please confirm that you have read the BASH Guide for Beginners as we suggested. |
Code:
#!/bin/bash Code:
# ./shell.sh |
I found a problem in what I posted. Ghostdog's solution may be more elegant, but I'm having a hard time following it....for example, where is the merged data being written to?
"while read" creates a loop that reads from standard input until it reaches end of file. But does it also terminate the loop when the second read statement reaches end of file? A simple test will verify this. Also, I don't think you need the file desciptors---ie you can just use the redirects with the actual file names? |
Quote:
Quote:
Quote:
I was feeling nostalgic about bash so i did it for "fun"... awk is still what i would use...;) |
All times are GMT -5. The time now is 03:40 AM. |