Sponsored Content
Top Forums UNIX for Dummies Questions & Answers awk, extract last line of multiple files Post 302464817 by Scrutinizer on Thursday 21st of October 2010 04:03:35 AM
Old 10-21-2010
You could use tail like this:
Code:
for i in *.txt
do 
  tail -1 "$i"
done

Your script can be adjusted like this
Code:
BEGIN {
  print "Starting script...";
}
  last_file != FILENAME && NR!=FNR {
  print last_line
}
{ last_line = $0
  last_file = FILENAME
}

END {
  print last_line;
  printf "\nEnding script...\n"
}

This User Gave Thanks to Scrutinizer For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to extract multiple strings from a line

Hi I have the following requirement. i have the following line from a log file one : two : Three : four : five : six : seven : eight :nine :ten Now can you pls help what i should do to get only the following output from the above line two : five : six : seven : Eight appreciate your... (3 Replies)
Discussion started by: vin_eme
3 Replies

2. Shell Programming and Scripting

extract multiple cloumns from multiple files; skip rows and include filenames; awk

Hello, I am trying to write a bash shell script that does the following: 1.Finds all *.txt files within my directory of interest 2. reads each of the files (25 files) one by one (tab-delimited format and have the same data format) 3. skips the first 10 rows of the file 4. extracts and... (4 Replies)
Discussion started by: manishabh
4 Replies

3. Shell Programming and Scripting

need help with post:extract multiple columns from multiple files

hello, I will would be grateful if anyone can help me reply to my post extract multiple cloumns from multiple files; skip rows and include filenames; awk Please see this thread. Thanks manishabh (0 Replies)
Discussion started by: manishabh
0 Replies

4. Shell Programming and Scripting

How to extract multiple line in a paragraph? Please help.

Hi all, The following lines are taken from a long paragraph: Labels of output orbitals: RY* RY* RY* RY* RY* RY* 1\1\GINC-COMPUTE-1-3\SP\UB3LYP\6-31G\C2H5Cr1O1(1+,5)\LIUZHEN\19-Jan-20 10\0\\# ub3lyp/6-31G pop=(nbo,savenbo) gfprint\\E101GECP\\1,5\O,0,-1.7 ... (1 Reply)
Discussion started by: liuzhencc
1 Replies

5. Shell Programming and Scripting

Split line to multiple files Awk/Sed/Shell Script help

Hi, I need help to split lines from a file into multiple files. my input look like this: 13 23 45 45 6 7 33 44 55 66 7 13 34 5 6 7 87 45 7 8 8 9 13 44 55 66 77 8 44 66 88 99 6 I want to split every 3 lines from this file to be written to individual files. (3 Replies)
Discussion started by: saint2006
3 Replies

6. UNIX for Dummies Questions & Answers

AWK, extract data from multiple files

Hi, I'm using AWK to try to extract data from multiple files (*.txt). The script should look for a flag that occurs at a specific position in each file and it should return the data to the right of that flag. I should end up with one line for each file, each containing 3 columns:... (8 Replies)
Discussion started by: Liverpaul09
8 Replies

7. UNIX for Dummies Questions & Answers

Using AWK: Extract data from multiple files and output to multiple new files

Hi, I'd like to process multiple files. For example: file1.txt file2.txt file3.txt Each file contains several lines of data. I want to extract a piece of data and output it to a new file. file1.txt ----> newfile1.txt file2.txt ----> newfile2.txt file3.txt ----> newfile3.txt Here is... (3 Replies)
Discussion started by: Liverpaul09
3 Replies

8. Shell Programming and Scripting

Compare multiple files, and extract items that are common to ALL files only

I have this code awk 'NR==FNR{a=$1;next} a' file1 file2 which does what I need it to do, but for only two files. I want to make it so that I can have multiple files (for example 30) and the code will return only the items that are in every single one of those files and ignore the ones... (7 Replies)
Discussion started by: castrojc
7 Replies

9. Shell Programming and Scripting

Extract multiple strings from line

Hello I have an output that has a string between quotes and another between square brackets on the same line. I need to extract these 2 strings Example line Device "nrst3a" attributes=(0x4) RAW SERIAL_NUMBER=SNL2 Output should look like nrst3a VD073AV1443BVW00083 I was trying with sed... (3 Replies)
Discussion started by: bombcan
3 Replies

10. Shell Programming and Scripting

awk - Multiple files - 1 file with multi-line data

Greetings experts, Have 2 input files, of which 1 file has 1 record per line; in 2nd file, multiple lines constitute 1 record; Hence declared the RS=";" Now in the first file which ends with ";" at each line of the line; But \nis also being considered as part of the data due to which I am... (1 Reply)
Discussion started by: chill3chee
1 Replies
GPIV_T-AVG(1)						      General Commands Manual						     GPIV_T-AVG(1)

NAME
gpiv_t-avg - Calculates time-averaged mean and variances of PIV data. SYNOPSIS
gpiv_t-avg [-dn | --dir_name dir basename] [-df | --first_dir N] [-dl | --last_dir N] [-fb | --file_basename file basename] [-ff | --first_file N] [-fl | --last_file N] [-fx | --file_prefix] [-h | --help] [-n | --none] [-p | --print] [-relrms] [-uv | --print] [-v | --version] DESCRIPTION
gpiv_t-avg calculates mean and variances from a series of piv data resulting into time-averaged values. If no parameters are defined at the command line, standard parameters will be used that are defined in the script. This program does not use the parameter resources from libg- piv. Options -dn | --dir_name dir base-name The dir base-name represents the directory name without its last number. It is supposed that the last number in the directory name is a counter. -df | --first_dir Defines the counter N of the first directory number at which the analyses starts. -dl | --last_dir Last directory number N at which the analyses ends. -fb | --file_base_name file base-name The filename has to be given without its .piv extension. The file base-name represents the file name without its last number, before the extension. If not -fx key is used, it is supposed that the last number in the file name is a counter. The output will be written to dir base-name/file base-name.ta_mean.piv and dirname/filename.ta_sdev.piv at which mean values and variances are written respec- tively or to dirname/filename.ta_U.piv and to dirname/filename.ta_V.piv if -uv is used. -ff | --first_file Defines the counter Nof first file number at which the analyses starts. -fl | --last_file Last file number N at which the analyses ends. -fx | --file_prefix Prefix numbering to file base name. -h | --help On-line help. -n | --none Suppresses real execution. -p | --print Prints parameters, command line options and input and output filenames to stdout. -relrms Prints relative rms, related to the absolute mean value. -uv Writes U and v displacements/velocities to separate outputs. -v | --version Prints version information to standard output, then exits successfully. SEE ALSO gpivtools AUTHOR
Gerber Van der Graaf 19 Januari 2005 GPIV_T-AVG(1)
All times are GMT -4. The time now is 10:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy