Thanks all, here's what i am trying to do, I am close but not there yet
I want to print the last line of script where the file doesn't terminate with a newline.
But checking if the last line is empty or not, i want to get the list, but it doesn't work exactly that way
Consider the following files, '$' in bold black is the command prompt, '$' in bold blue is the formatting character from -e flag
Both files b.sh and c.sh seem to have the last line as 'apple', but in c.sh the end of file is on the same line as 'apple' and in b.sh it's in the next line
I want to print filename and last line for only files of type c.sh and not b.sh
The above awk command doesn't differentiate between b.sh and c.sh
Don't know if this will behave the same way on your OS, but on my ubuntu, if i tail -1 c.sh | wc -l i will get a 0 instead of 1 when there is no end of line.
So this may help to detect such file with no newline character.(A check that the file is not empty should be carried out as well)
hi ctsgnb, this c.sh has only one line without having a new line that's why "wc -l" returns zero. c.sh can have multiple lines without having newline at the end of the file, so checking for zero doesn't work
I want to print list of filenames along with their last line where the file doesn't end with a new line
Thanks
Hi,
I have filename as:
010020001_S-FOR-Sort-SYEXC_20180109_062320_0100.x937
I need first 5 words of my filename along with the respective delimiters:
I tried this:
f=010020001_S-FOR-Sort-SYEXC_20180109_062320_0100.x937
echo $f | awk -F '' '{print $1$2$3$4$5}'
010020001SFORSortSYEXC
... (11 Replies)
I have files named with different prefixes. From each I want to extract the first line containing a specific string, and then print that line along with the prefix.
I've tried to do this with a while loop, but instead of printing the prefix I print the first line of the file twice.
Files:... (3 Replies)
I have a file and when I match the word "initiators" in the first column I need to be able to print the rest of the columns in that row. This is fine for the most part but on occasion the "initiators" line gets wrapped to the next line. Here is a sample of the file.
caw-enabled ... (3 Replies)
Today I needed to take a look through a load of large backup files, so I wrote the following line to find them, order them by size, and print the file sizes in GB along with the filename. What happened was odd, the output was all as expected except for the first output line which had the filename... (4 Replies)
Hi all,
From a while loop I am reading a sorted file where I want to print only the lines that have $1 match and $2 only when the difference from $2 from the previous line is > 30.
Input would be like ...
AN237 010 193019 0502 1 CSU Amoxycillin
AN237 080 ... (2 Replies)
I can got the filename with this script. it's only show "-" in result.
cut -d , -f7 CSV_d.* | awk 'OFS=":"{print FILENAME,substr($1,1,8),substr($1,9,2),substr($1,11,2),substr($1,13,2)}' | sort |uniq (2 Replies)
Hi all,
I've a script that uses awk to parse the output of wget during a database update. The code I use is:
wget -c ftp://ftpsite/file 2>&1 | awk '/0%/ {print}'But this spits out each progress line on a new line:
37250K .......... .......... .......... .......... .......... 80% 10.9M 1s
... (2 Replies)
I'm trying to clean up my samba share and need to print the found file or print the path of the image it tried to searched for. So far I have this but can't seem to get the logic right. Can anyone help point me in the right direction?
for FILE in `cat list`; do
if ;
then
... (1 Reply)
Ok I have a file with hundreds of lines, four columns, space delimited, TESTB.TXT for example
TESTB.TXT
---
AA ZZ 12 34
BB YY 56 78
CC XX 91 23
DD VV 45 67
---
I want a new file that has 7 columns, the first four are identical, and the next 3 are the last three of the next line...so... (5 Replies)
how to print any required line by its line no using awk and its NR variable
for eg:
------------
121343
adfdafd
21213sds
dafadfe432
adf.adf%adf
---------------
requied o/p if give num=3 it print:
21213sds
-------------------------------------- (2 Replies)