Sponsored Content
Full Discussion: awk -v dilema
Top Forums Shell Programming and Scripting awk -v dilema Post 302954602 by jville on Wednesday 9th of September 2015 09:42:38 AM
Old 09-09-2015
awk -v dilema

Hello Folks,
How do I use awk for passing, seraching and returning certain lines above a pattern variable

Code:
 
numbers.txt
 
one
two
three
four
five
six
seven
eight
nine
ten
eleven
twelve
thirteen
fourteen
fifteen

Code:
for text in ten thirteen sixteen
do
        awk -v wText="$text" '{a[++i]=$0;}/wText/{for(j=NR-4;j<=NR;j++)print a[j];}' numbers.txt > tmpfile
done

Output needed as below
Code:
six
seven
eight
nine
ten
 
nine
ten
eleven
twelve
thirteen


Last edited by jville; 09-09-2015 at 11:27 AM..
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

scripting dilema

I have a script which writes to a file using date and the end filename would be filename`date +%d%b%y. Now when i have 2 files ( 2 days ), i want to compare them using an automated script and then put the differences if there are into another file. Can someone please help me how to automize... (4 Replies)
Discussion started by: family_guy
4 Replies

2. Shell Programming and Scripting

Awk problem: How to express the single quote(') by using awk print function

Actually I got a list of file end with *.txt I want to use the same command apply to all the *.txt Thus I try to find out the fastest way to write those same command in a script and then want to let them run automatics. For example: I got the file below: file1.txt file2.txt file3.txt... (4 Replies)
Discussion started by: patrick87
4 Replies

3. Shell Programming and Scripting

scripting/awk help : awk sum output is not comming in regular format. Pls advise.

Hi Experts, I am adding a column of numbers with awk , however not getting correct output: # awk '{sum+=$1} END {print sum}' datafile 2.15291e+06 How can I getthe output like : 2152910 Thank you.. # awk '{sum+=$1} END {print sum}' datafile 2.15079e+06 (3 Replies)
Discussion started by: rveri
3 Replies

4. Shell Programming and Scripting

Read content between xml tags with awk, grep, awk or what ever...

Hello, I trying to extract text that is surrounded by xml-tags. I tried this cat tst.xml | egrep "<SERVER>.*</SERVER>" |sed -e "s/<SERVER>\(.*\)<\/SERVER>/\1/"|tr "|" " " which works perfect, if the start-tag and the end-tag are in the same line, e.g.: <tag1>Hello Linux-Users</tag1> ... (5 Replies)
Discussion started by: Sebi0815
5 Replies

5. Shell Programming and Scripting

Problem with awk awk: program limit exceeded: sprintf buffer size=1020

Hi I have many problems with a script. I have a script that formats a text file but always prints the same error when i try to execute it The code is that: { if (NF==17){ print $0 }else{ fields=NF; all=$0; while... (2 Replies)
Discussion started by: fate
2 Replies

6. Shell Programming and Scripting

awk command to compare a file with set of files in a directory using 'awk'

Hi, I have a situation to compare one file, say file1.txt with a set of files in directory.The directory contains more than 100 files. To be more precise, the requirement is to compare the first field of file1.txt with the first field in all the files in the directory.The files in the... (10 Replies)
Discussion started by: anandek
10 Replies

7. Shell Programming and Scripting

HELP with AWK one-liner. Need to employ an If condition inside AWK to check for array variable ?

Hello experts, I'm stuck with this script for three days now. Here's what i need. I need to split a large delimited (,) file into 2 files based on the value present in the last field. Samp: Something.csv bca,adc,asdf,123,12C bca,adc,asdf,123,13C def,adc,asdf,123,12A I need this split... (6 Replies)
Discussion started by: shell_boy23
6 Replies

8. Shell Programming and Scripting

Passing awk variable argument to a script which is being called inside awk

consider the script below sh /opt/hqe/hqapi1-client-5.0.0/bin/hqapi.sh alert list --host=localhost --port=7443 --user=hqadmin --password=hqadmin --secure=true >/tmp/alerts.xml awk -F'' '{for(i=1;i<=NF;i++){ if($i=="Alert id") { if(id!="") if(dt!=""){ cmd="sh someScript.sh... (2 Replies)
Discussion started by: vivek d r
2 Replies

9. Shell Programming and Scripting

awk output yields error: awk:can't open job_name (Autosys)

Good evening, Im newbie at unix specially with awk From an scheduler program called Autosys i want to extract some data reading an inputfile that comprises jobs names, then formating the output to columns for example 1. This is the inputfile: $ more MapaRep.txt ds_extra_nikira_usuarios... (18 Replies)
Discussion started by: alexcol
18 Replies
eucJP(5)						Standards, Environments, and Macros						  eucJP(5)

NAME
eucJP, eucjp - map between Japanese EUC and character set DESCRIPTION
In SunOS and JFP, Japanese EUC (Extended UNIX code) is used as character code system expressing multi-byte languages including Japanese character in the "ja" locale. This manual page shows map between Japanese EUC and character set. The following is a map table for Japanese EUC and character set (SS2 stands for 0x8e, and SS3 stands for 0x8f ). Table 1 Japanese EUC character set 0x00 - 0x19 JIS X 0201-1976 function character set 0x20 JIS X 0201-1976 space char- acter 0x21 - 0x7e JIS X 0201-1976 figure char- acter set for roman charac- ter 0x7f JIS X 0201-1976 erase char- acter 0x80 - 0x9f ISO 6429 C1 control charac- ter (except for 0x8e, 0x8f) SS2 0xa1 - 0xdf JIS X 0201-1976 figure char- acter set for katakana (except for an area of unde- fined character E/0 - F/14) SS3 0xa1a1 - 0xa1fe JIS X 0212-1990 (1 ku 1 ten - 1 ku 94 ten) SS3 0xa2a1 - 0xa2fe JIS X 0212-1990 (2 ku 1 ten - 2 ku 94 ten) : : : : SS3 0xf3a1 - 0xf3fe JIS X 0212-1990 (83 ku 1 ten - 83 ku 94 ten) SS3 0xf4a1 - 0xf4fe JIS X 0212-1990 (84 ku 1 ten - 84 ku 94 ten) 0xa1a1 - 0xa1fe JIS X 0208-1990 (1 ku 1 ten - 1 ku 94 ten) 0xa2a1 - 0xa2fe JIS X 0208-1990 (2 ku 1 ten - 2 ku 94 ten) : : : : 0xf3a1 - 0xf3fe JIS X 0208-1990 (83 ku 1 ten - 83 ku 94 ten) 0xf4a1 - 0xf4fe JIS X 0208-1990 (84 ku 1 ten - 84 ku 94 ten) Each character set corresponds with Japanese EUC code set numbers as follows. Table 2 character set (coding charac- Japanese EUC extended code set no. ter set) JIS X 0201 figure character 0 set for roman character JIS X 0208-1990 1 JIS X 0201 figure character 2 set for katakana JIS X 0212-1990 3 NOTES
In Japanese EUC area below has special meaning. Table 3 Japanese EUC area of character set meaning SS3 0xf3a1 - 0xf4fe JIS X 0212-1990 83 ku Vender Defined Character - 84 ku (IBM extension character not included in JIS X 0212-1990) SS3 0xf5a1 - 0xfefe User Defined Character 11 ku - 20 ku 0xada1 - 0xadfe JIS X 0208-1990 13 ku Vender Defined Character (special symbols) 0xf5a1 - 0xfefe User Defined Character 1 ku - 10 ku SEE ALSO
PCK(5) SunOS 5.10 12 June 2000 eucJP(5)
All times are GMT -4. The time now is 03:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy