Sponsored Content
Contact Us Post Here to Contact Site Administrators and Moderators How to Post in the The UNIX and Linux Forums Usage of tail command in .awk Post 302901358 by Venkata Madhu on Tuesday 13th of May 2014 01:29:31 PM
Old 05-13-2014
Usage of tail command in .awk

Hi,

I want to do file format using awk script, for that i wan to use 'tail'. Here is the scenario. I will be having set of files in a directory. Those files i need to write to another directory with same file name, but while writing the file to out directory, i need to write the last line as first line and the rest will follow in the same order. For example, the file has below content
HTML Code:
one
two
three
four
The file with the same name in output directory should be like
HTML Code:
four
one
two
three
I tried like below, but wasn't working

Code:
BEGIN {
	while ( ( "ls -l "ARGV[1] | getline line ) > 0 ) 
	{
		n = split(line, fileName, " ")
		if (fileName[n] > 0)
		{
			count=0
			while ((getline < (ARGV[1] "/" fileName[n]))>0) 
			{				
				dLine = $0
				if (count == 0) 
				{
					#temp = `$(tail -1 $(ARGV[1] "/" fileName[n]))`
					sed -ne 1 $ARGV[1] "/" fileName[n] > ARGV[2] "/" fileName[n]
					printf "\n" >> ARGV[2] "/" fileName[n]
					printf dLine >> ARGV[2] "/" fileName[n]
					printf "\n" >> ARGV[2] "/" fileName[n]
				}
				
				if (count != 0 && substr(dLine ,1,1) != "H")
				{
					printf dLine >> ARGV[2] "/" fileName[n]
					printf "\n" >> ARGV[2] "/" fileName[n]
				}
				count = count+1
			};	
		}
	}
}

Venkata Madhu
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

tail command

Hi , I have found a interesting thing about tail command: when I tried to use 'tail -1 *' to look at every file with the current derectory, I only got one line of result of one file. But if I use 'head -1 *', I would get multiple lines. Is there a way to do get multiple lines with 'tail -1 *'... (3 Replies)
Discussion started by: whatisthis
3 Replies

2. Shell Programming and Scripting

tail command..

I was wondering how can I do this I have file myfile.txt wc -l is: 5 000 000 I have to remove first 1 000 000 lines from header.. I tryed with tail -4000000 myfile.txt>newfile.txt but it does not work... any help?? (2 Replies)
Discussion started by: amon
2 Replies

3. Shell Programming and Scripting

awk and grep command usage

hi Can anyone explain me how these two commands awk and grep works in a ksh shell Thanks Babu (1 Reply)
Discussion started by: ksmbabu
1 Replies

4. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

5. Shell Programming and Scripting

Help with tail command

Hi All, My query seems to be silly but Iam unable to find where the exact problem lies. I have a script to unzip set of files here is the script #!/bin/ksh Count=`cat /home/gaddamja/Tempfile | wc -l` while do Filename=`cat /home/gaddamja/Tempfile |tail -$Count | head -1` cd... (7 Replies)
Discussion started by: jagadish_gaddam
7 Replies

6. UNIX for Dummies Questions & Answers

Command to display the space usage (memory usage) of a specific directory.

Hi all, Can you please tell me the command, with which one can know the amount of space a specific directory has used. df -k . ---> Displays, the amount of space allocated, and used for a directory. du -k <dir name> - gives me the memory used of all the files inside <dir> But i... (2 Replies)
Discussion started by: abhisheksunkari
2 Replies

7. Shell Programming and Scripting

usage of AWK command under perl script

i have two files as shown below t1.txt: argument1 argu2 argu37 t2.txt: 22 33 44 i want o/p as argument1 22 argu2 33 argu37 44 i am trying to merge two file under perl script using following system("paste t1.txt t2.txt | awk... (3 Replies)
Discussion started by: roopa
3 Replies

8. Shell Programming and Scripting

tail command help

Hi does anyone know how to create a file using the tail command? My book has this file I need to create and it says to use the tail command and that it is possible but I have no idea. Thanks. (4 Replies)
Discussion started by: drew211
4 Replies

9. Shell Programming and Scripting

usage of Awk command for output

Hi Experts, I have a Text file generated as below; <NAME> NEW#<technicalName><TAB> <Version> OLD#<technicalName><TAB> <Version> e.g. CH_PPV_AUDIT_DISTRIBUTOR NEW#EL_CFG_FTP_DISTRIBUTOR 2.1.0.upc2 OLD#EL_CFG_FTP_DISTRIBUTOR 2.1.0.upc1... (19 Replies)
Discussion started by: rajangupta2387
19 Replies

10. UNIX for Beginners Questions & Answers

Tail -f Command help

Hi Team, Can anyone help me here: I have to access server logs via putty and these logs file is a trailing file (continously updating) with ERROR and WARNINGS... I need to know if I can pull this trailing file to a local drive so that I can do some higlighting on some keywords through Notepad... (13 Replies)
Discussion started by: jitensetia
13 Replies
Tcl_WrongNumArgs(3)					      Tcl Library Procedures					       Tcl_WrongNumArgs(3)

__________________________________________________________________________________________________________________________________________________

NAME
Tcl_WrongNumArgs - generate standard error message for wrong number of arguments SYNOPSIS
#include <tcl.h> Tcl_WrongNumArgs(interp, objc, objv, message) ARGUMENTS
Tcl_Interp interp (in) Interpreter in which error will be reported: error message gets stored in its result object. int objc (in) Number of leading arguments from objv to include in error message. Tcl_Obj *const objv[] (in) Arguments to command that had the wrong number of arguments. const char *message (in) Additional error information to print after leading arguments from objv. This typically gives the acceptable syntax of the command. This argument may be NULL. _________________________________________________________________ DESCRIPTION
Tcl_WrongNumArgs is a utility procedure that is invoked by command procedures when they discover that they have received the wrong number of arguments. Tcl_WrongNumArgs generates a standard error message and stores it in the result object of interp. The message includes the objc initial elements of objv plus message. For example, if objv consists of the values foo and bar, objc is 1, and message is "fileName count" then interp's result object will be set to the following string: wrong # args: should be "foo fileName count" If objc is 2, the result will be set to the following string: wrong # args: should be "foo bar fileName count" Objc is usually 1, but may be 2 or more for commands like string and the Tk widget commands, which use the first argument as a subcommand. Some of the objects in the objv array may be abbreviations for a subcommand. The command Tcl_GetIndexFromObj will convert the abbreviated string object into an indexObject. If an error occurs in the parsing of the subcommand we would like to use the full subcommand name rather than the abbreviation. If the Tcl_WrongNumArgs command finds any indexObjects in the objv array it will use the full subcommand name in the error message instead of the abbreviated name that was originally passed in. Using the above example, let us assume that bar is actually an abbreviation for barfly and the object is now an indexObject because it was passed to Tcl_GetIndexFromObj. In this case the error message would be: wrong # args: should be "foo barfly fileName count" SEE ALSO
Tcl_GetIndexFromObj KEYWORDS
command, error message, wrong number of arguments Tcl 8.0 Tcl_WrongNumArgs(3)
All times are GMT -4. The time now is 04:49 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy