n=1
echo "$FILE" |
while read line
do
echo "$n) $line"
n=`expr $n + 1`
But really, i dont want to number the blank lines.
What i've tried is to use sed commands to the FILE before i pipe its contents into the while, but sed just bunchs the contents together and my code reads it at one line..
The sed command sed 'nd' reads every other line right? Unfortuantely for me that doesnt work either..
In that case just modify your script to validate the string.
line_no=1
while read each_line
do
if [ ! -z $each_line ]
then
line_no=`expr $line_no + 1`
echo "$line_no $each_line"
fi
done < input_file > output_file
U guys make things way to complecated. hehe. i just used sed -n '1p' for the first line..
But im wondering..Is there a way to loop through so i dont have to use a different varaible for a new line each time..? Because my sed pipeline is kinda long..
Example
Var1=$( cat $FILE | sed ..... | sed -n '1p' )
Var2=$( cat $FILE | sed ..... | sed -n '2p' )
OR can i have the long sed pipeline to be a varaible..To then have:
Var3=$( cat $FILE | longVar | sed -n '3p' )
Also..A command that would be really extemely soo very valuble to me would be to print lines 1 - 12 or so at once.
sed -n '/[1-12]/'
or something like that, because if i were to have sed -n '1-12p' it wouldnt include the blank lines..understand? I guess i have no choice to do it seperately. grr.
Hi! If I were you, I would try the suggested steps to strip off the blank lines then from there you can make further actions on your file.
I guess your file is not that big so why not paste it here with code tags. Paste your exact input file(if that's possible) and then your expected output file, just to make things clear.
i might get in trouble if i post the actual text file and also the sed pipeline.
I think i have it figured out tho..And i dont want to quit until its done, so this is an all nighter for me..But as of this moment i've already done what i said i was going to do and i have a consecutive amount of varaibles. And it works for 1 of my text files! But i need to get it to work for all of them and i think all i have to do is delete a space from the files LOL. Its like im globally reading 1 file for all the files i need. So everything is changed if i change 1 thing.