Problem related to awk


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Problem related to awk
# 1  
Old 07-23-2007
Problem related to awk

Hi,

can anyone explain me the following command.

awk '{y=x "\n" $0; x=$0};END{print y}' file_name


Regards
Rochit
# 2  
Old 07-23-2007
Hey Rochit...

As a one-liner, It looks like a convoluted way to prepend a carriage return to the text input from "file_name" (which would be the path to your text file). The same result can be obtained many ways, one would be:

awk '{print "\n" $0}' file_name

The text of file_name is assigned to $0, which is concatenated with the carriage return "\n" and printed to the screen.

The example you provided just adds the variables x and y. x is assigned the text value of the input for $0. Then a carriage return "\n" is prepended to x. Then x is assigned to y, which is printed to the screen.

Hope this helps some....Cassj
# 3  
Old 07-23-2007
hi

the function of one-liner i have given is same as

tail -2 file_name

but the thing is I am not getting how is it displaying only 2 records.... I am not able to understand its working....

Regards
Rochit
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk related question

awk -F ";" 'FNR==NR{a=$1;next} ($2 in a)' server.list datafile | while read line do echo ${line} done when i run the above, i get this: 1 SERVICE NOTIFICATION: nagiosadmin skysmart-01.sky.net .... instead of: SERVICE NOTIFICATION: nagiosadmin skysmart-01.sky.net .... can... (4 Replies)
Discussion started by: SkySmart
4 Replies

2. Solaris

Problem to understand METADEVICE and related commands

Hi everyone, I'm new with solaris administration. I have just discovered the notion of METADEVICE and I really don't understand it. Can any one please explain it to me or give me useful link ? I also want to know more about these commandes: metainit metadb metaattach Thank you ... (1 Reply)
Discussion started by: adilyos
1 Replies

3. Shell Programming and Scripting

awk related question

awk "/^<Mar 31, 2012 : /,0" /app/blah.log can someone please help me figure out why the above command isn't pulling anything out from the log? basically, i want it to pull out all records, from the very first line that starts with the date "Mar 31, 2012" and that also has a time immediately... (4 Replies)
Discussion started by: SkySmart
4 Replies

4. Shell Programming and Scripting

Problem related to shell script

I am new in shell script.I want to write a shell script to read username and password from file and compare it with the username and password which is entered by the GUI application. (1 Reply)
Discussion started by: shubhig15
1 Replies

5. Programming

and again, socket() related problem...

Dear All, I've searched many topics and googled many web-pages, but still I didn't found solution to this problem. I want to set timeout for connect(). The thing is, that my code works only on BSD, on Linux (tested on SuSE box) it freezes at connect() call :( bool SomeFunc(std::string... (1 Reply)
Discussion started by: sggkxv
1 Replies

6. Solaris

Hardware Raid related problem

Dear All I would Like to know that if suppose c1t0d0 is of 72 gb hard disk and system boot from this hard disk and c1t1d0 is of 147gb hard disk. Can we implement hardware raid (Mirror) between these two hard disks of different capacity if raid crontroller is present in the server Kind regards (4 Replies)
Discussion started by: girish.batra
4 Replies

7. UNIX for Dummies Questions & Answers

awk related query

hi, I have to extract a column from a file and then updated that column..?? Now i can use wak for extracting it and then how to update it.. $ awk' {print $5}' input_file Can i use sed command here piping it to the output from the awk command.. (2 Replies)
Discussion started by: abhisek.says
2 Replies

8. UNIX for Advanced & Expert Users

DOS messaging question - related to UNIX process problem

Hi, This is a strange request. I know there is some sort of crude DOS tool that allows you to communicate to another PC either using its IP adress or PC name. But I can't remember where aor what its called, any ideas? Reason for asking here, Someone has telnet'd on a UNIX server I have... (0 Replies)
Discussion started by: nhatch
0 Replies

9. Shell Programming and Scripting

what is problem with this small shell script.. case statement related

Hi All, this small script is written to recognize user input character.. it is in small case .. upeer case or is a number... but when i input first capital letter say A.. it always gives small character.... what is the problem. #!/bin/bash echo "Enter the character" read a case $a in )... (2 Replies)
Discussion started by: johnray31
2 Replies

10. Shell Programming and Scripting

Crontab Related problem

Hi Following is the script which runs from command prompt....... but when I schedule it in crontab , its showing some error ( mentioned after this piece of code) #!/bin/ksh PATH=/usr/bin:/usr/ucb:/etc:. export PATH JAVA_HOME=/opt/bea/jdk131; export JAVA_HOME ANT_HOME=/opt/bea/ant... (1 Reply)
Discussion started by: pankajkrmishra
1 Replies
Login or Register to Ask a Question