Sunday, April 28, 2024
13
rated 0 times [  13] [ 0]  / answers: 1 / hits: 24071  / 2 Years ago, sat, july 2, 2022, 9:03:22

All what i want is to specify a certain number of line like this lineNumberIs=3 and to tell while read to start out of this third line or what ever line number and fetching lines after wards to execute some commands later on the fetched lines
Something like that



 while read line from $lineNumberIs
do
**some commands not just echo nor printing on the screen**
done < $dataFile

More From » command-line

 Answers
5
while IFS= read -r line; do
# ...
done < <(tail -n "+$lineNumberIs" $dataFile)


tail -n +K (with the plus sign) tells tail to start at the specified line number (see the man page).



The <(...) bit is a process substitution. It lets you specify a command sequence and let bash read from it like a file. It's very handy when you want to avoid the effect of the subshell created in a pipeline.



IFS= read -r is used to read the line exactly s it appears in the file, with no spaces or escape sequences removed.


[#31454] Sunday, July 3, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
exceeeelh

Total Points: 21
Total Questions: 109
Total Answers: 120

Location: Marshall Islands
Member since Wed, Jan 5, 2022
2 Years ago
exceeeelh questions
Sun, Nov 20, 22, 17:08, 1 Year ago
Sat, Jan 1, 22, 08:04, 2 Years ago
Wed, May 12, 21, 05:11, 3 Years ago
;