Ask Question Forum:
Model Library:2025-02-08 Updated:A.I. model is online for auto reply question page
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by hankknight
at 2024-11-18 05:51:38
Point:500 Replies:11 POST_ID:828805USER_ID:11403
Topic:
Linux;;
This loops through a file starting at the beginning:
#!/bin/bashwhile read LINEdo if [ $(( i )) -lt 5 ]; then i=$((i+1)) echo $LINE else break fidone <"$1" 1:2:3:4:5:6:7:8:9:10:
How can I loop through the file starting at the end and going backward one line at a time? Can -tail be used for this? I do not want to read only the last 5 lines because I want to use a more complicated condition than the one above. Instead, I want to read the file backwards, starting at the last line then moving up one line at a time.
Expert: woolmilkporc replied at 2024-11-18 11:50:22
To make this thread complete:
"$(tac $1)" must be enclosed in double quotes in order to keep the newline characters from being stripped off by the shell.
wmp
"$(tac $1)" must be enclosed in double quotes in order to keep the newline characters from being stripped off by the shell.
wmp
Author: hankknight replied at 2024-11-18 11:04:46
<<< $(tac $1)
That does not seem to be working on my OS. I have posted a question about that here:
http://www.experts-exchange.com/OS/Linux/Q_28297339.html
That does not seem to be working on my OS. I have posted a question about that here:
http://www.experts-exchange.com/OS/Linux/Q_28297339.html
Expert: duncanb7 replied at 2024-11-18 10:24:34
woolmilkporc,
Yes, it is correct no need for creating temp file from your code.
I tried your code at my side, but the output of result is different from my result.
hankknight,
could you also try it if you have time ?
Duncan
Yes, it is correct no need for creating temp file from your code.
I tried your code at my side, but the output of result is different from my result.
hankknight,
could you also try it if you have time ?
Duncan
Expert: woolmilkporc replied at 2024-11-18 10:14:37
>> Is there a way to do that without creating a temporary junk file <<
Yes, and please see my last comments to your thread http://www.experts-exchange.com/OS/Linux/Q_28295367.html where I already provided this solution.
#!/bin/bash
while read LINE
do
if [ $(( i )) -lt 5 ];
then
i=$((i+1))
echo $LINE
else break
fi
done <<< $(tac $1)
Yes, and please see my last comments to your thread http://www.experts-exchange.com/OS/Linux/Q_28295367.html where I already provided this solution.
#!/bin/bash
while read LINE
do
if [ $(( i )) -lt 5 ];
then
i=$((i+1))
echo $LINE
else break
fi
done <<< $(tac $1)
Expert: duncanb7 replied at 2024-11-18 08:45:58
Thanks
Have a nice day
Duncan
Have a nice day
Duncan
Expert: duncanb7 replied at 2024-11-18 08:40:07
I think it already asnwered your question
you can add rm -rf junk.txt in your script to delete the temp file .
creating a temp file is not harmful
you can add rm -rf junk.txt in your script to delete the temp file .
creating a temp file is not harmful
Author: hankknight replied at 2024-11-18 08:34:13
That does what I want. Is there a way to do that without creating a temporary junk file?
Accepted Solution
Expert: duncanb7 replied at 2024-11-18 08:20:44
500 points EXCELLENT
Is it what you want ? what is last 5 line meaning
You want display the file in reverse order and at the last-5 line ?
You want display the file in reverse order and at the last-5 line ?
#!/bin/bashtac $1 >junk.txtwhile read LINEdo if [ $(( i )) -lt 5 ]; then i=$((i+1)) echo $LINE else break fidone <junk.txt 1:2:3:4:5:6:7:8:9:10:11:
Expert: duncanb7 replied at 2024-11-18 08:10:30
what command you input and what error is ?
Please send it out
Please send it out
Author: hankknight replied at 2024-11-18 07:57:09
How can I do this with the code I posted? This does NOT work:
#!/bin/bashwhile read LINEdo if [ $(( i )) -lt 5 ]; then i=$((i+1)) echo $LINE else break fidone < tac "$1" 1:2:3:4:5:6:7:8:9:10:
Expert: duncanb7 replied at 2024-11-18 07:36:50
You want to display the file in reverse order , Right ?
if so , using tac command
tac youfile.txt>output,txt
some Linux distrubtion, tail -r yourfile.txt that also works
if so , using tac command
tac youfile.txt>output,txt
some Linux distrubtion, tail -r yourfile.txt that also works