Answer by Janyee for Looping through the content of a file in Bash
My solution is:Combining sed and wc commands, counting the first and last lines, and then looping through each line:end=$(wc -l peptides.txt | cut -d '' -f 1)currentLine=1while [ $currentLine -le $end...
View ArticleAnswer by Lasse Jenssen for Looping through the content of a file in Bash
Use the "awk" command to split instead.When using the suggestion above splitting my file took about 5 minutes.FILENAME=file-to-splittwhile read LINE; do bankid=`echo $LINE | cut -d',' -f1` echo $LINE...
View ArticleAnswer by Sap for Looping through the content of a file in Bash
Alarm and Achtung!Most (all?) of the answers based on the "read" builtin are wrong beacause they will skip the last line of the file if that line doesn't end with an end-of-line character (which i LF...
View ArticleAnswer by Tirsvad for Looping through the content of a file in Bash
Some cases the while read from file get "exhausted"Then I map the the file to an array before using while loopmapfile -t lines < "$file"for line in "${lines[@]}"; do printf "${line}"done
View Article--- Article Not Found! ---
*** *** *** RSSing Note: Article is missing! We don't know where we put it!!. *** ***
View Article--- Article Not Found! ---
*** *** *** RSSing Note: Article is missing! We don't know where we put it!!. *** ***
View ArticleAnswer by jamlee for Looping through the content of a file in Bash
subshell is problem when use pipe.while read line do # do something with $line heredone <<<$(cat peptides.txt)
View ArticleAnswer by Brandon Kauffman for Looping through the content of a file in Bash
I use:for i in $(cat peptides.txt); do echo $i; done;PS: I know this is late
View ArticleAnswer by xekon for Looping through the content of a file in Bash
This might be the simplest answer and maybe it don't work in all cases, but it is working great for me:while read line;do echo "$line";done<peptides.txtif you need to enclose in parenthesis for...
View ArticleAnswer by hamou92 for Looping through the content of a file in Bash
I like to use xargs instead of while. xargs is powerful and command line friendlycat peptides.txt | xargs -I % sh -c "echo %"With xargs, you can also add verbosity with -t and validation with -p
View ArticleLooping through the content of a file in Bash
How do I iterate through each line of a text file with Bash? With this script: echo "Start!" for p in (peptides.txt) do echo "${p}" done I get this output on the screen: Start! ./runPep.sh: line 3:...
View ArticleAnswer by Warren Young for Looping through the content of a file in Bash
cat peptides.txt | while read line do # do something with $line here done and the one-liner variant: cat peptides.txt | while read line; do something_with_$line_here; done
View ArticleAnswer by Bruno De Fraine for Looping through the content of a file in Bash
One way to do it is: while read p; do echo "$p" done <peptides.txt As pointed out in the comments, this has the side effects of trimming leading whitespace, interpretting backslash sequences, and...
View ArticleAnswer by Stan Graves for Looping through the content of a file in Bash
Option 1a: While loop: Single line at a time: Input redirection #!/bin/bash filename='peptides.txt' echo Start while read p; do echo $p done < $filename Option 1b: While loop: Single line at a time:...
View ArticleAnswer by mightypile for Looping through the content of a file in Bash
This is no better than other answers, but is one more way to get the job done in a file without spaces (see comments). I find that I often need one-liners to dig through lists in text files without the...
View ArticleAnswer by Sine for Looping through the content of a file in Bash
#!/bin/bash # # Change the file name from "test" to desired input file # (The comments in bash are prefixed with #'s) for x in $(cat test.txt) do echo $x done
View ArticleAnswer by Jahid for Looping through the content of a file in Bash
Use a while loop, like this: while IFS= read -r line; do echo "$line" done <file Notes: If you don't set the IFS properly, you will lose indentation. You should almost always use the -r option with...
View ArticleAnswer by Whome for Looping through the content of a file in Bash
Here is my real life example how to loop lines of another program output, check for substrings, drop double quotes from variable, use that variable outside of the loop. I guess quite many is asking...
View ArticleAnswer by Alan Jebakumar for Looping through the content of a file in Bash
@Peter: This could work out for you- echo "Start!";for p in $(cat ./pep); do echo $p done This would return the output- Start! RKEKNVQ IPKKLLQK QYFHQLEKMNVK IPKKLLQK GDLSTALEVAIDCYEK...
View ArticleAnswer by dawg for Looping through the content of a file in Bash
Suppose you have this file: $ cat /tmp/test.txt Line 1 Line 2 has leading space Line 3 followed by blank line Line 5 (follows a blank line) and has trailing space Line 6 has no ending CR There are four...
View Article