6
The following command:
head -n 1 $FILE | tail -n 1
Pulls text from line one of $FILE
. The format of each line in $FILE
is as follows:
1 2 3 4 2 3 3 4 5 4 5 6 7 8 9
As you can see, each character is separated by a single space. Each group is separated by two spaces. Using sed
I need to remove the single spaces, and convert the double spaces into single spaces.
The text in $FILE
is created by a for loop nested inside another for loop. So the text data on each line is redirected >>
to $FILE
from the main for loop after the nested has run it's course. Each character/number in the text string is the result of the nested for loop completing once. Then the main for loop sends the nested for loop's output to $FILE
.
So an example of pseudo-code would be:
for i in $(seq 1 $RANDOM)
do
for n in {1..10}
do
$do_something
done
$do_something_else
done >> $FILE
head -n 1 $FILE | tail -n 1 | (sed command here)
How the code above is structured makes no difference to the need here. I simply seek a lightweight method for the text manipulation described above regarding spaces. If this has been asked before, my apologies. I could not find it in my queries.
It's not necessary to use
tail
sincehead
is only giving you one line anyway. – Paused until further notice. – 2016-10-13T19:51:05.287I determine what is necessary in my scripts. Using tail is merely a failsafe to prevent unwanted activity. In the way I am using
head
the "1" is actually inside another for loop as well and the line number is determined by $i. The code in the question is just pseudo-code and nothing more. – Yokai – 2016-10-14T05:59:42.970