Script to Read lines and print


 
Thread Tools Search this Thread
Operating Systems AIX Script to Read lines and print
# 1  
Old 04-03-2016
Script to Read lines and print

Dears,

I am trying to write a script to read the lines from a file in AIX Server.

Below are the contents of the file. To explain, first part before = is path and second part is number.

i am trying to write the script to print the path and count where count>100. any help must be appreciated

Output for my below data is

Code:
/Slave/13578/temp/1 = 100
 ./Slave/13578/temp/1=300 
 ./2390/15248/Test/Test1/20160331220000= 131 
 ./2390/15248/Test/Test1/20160331220000= 131

FILE:
Code:
./KING/12546/Test= 3 

 ./Queen/11980= 6 

 ./KING/12844/Test= 0 

 ./Slave/13578/temp/1=300 

 ./Queen/11982= 0 

 ./Queen/11984= 0 

 ./KING/12567/log= 0 

 ./2390/15248/Test/Test1/20160331220000= 131 

 ./Slave/4455/log/1= 0 

 ./Queen/11989= 0


Last edited by RudiC; 04-03-2016 at 02:44 PM.. Reason: Added code tags (where I thought they should be!)
# 2  
Old 04-03-2016
Please use code tags as required by forum rules!

Any attempts from your side? Any preferred tool to deploy?

And, is it safe to assume "count" is the field you call "number" in your explanation? Where does the first line in your desired output come from? It is not in your input file, and, if it were, it wouldn't satisfy the condition. And, why the duplicate output of the last line?
# 3  
Old 04-11-2016
Code:
awk -F " *= *" '$2>100 {sub(" +","",$1); print "path="$1, "count="$2}' file

# 4  
Old 04-11-2016
The output requested could almost be achieved just using:
Code:
awk -F '= *' '$2>=100' FILE

To get the output specified in the textual requirements, that would be:
Code:
awk -F '= *' '$2>100' FILE

but that would just produce the output:
Code:
 ./Slave/13578/temp/1=300 
 ./2390/15248/Test/Test1/20160331220000= 131

since 100 is not greater than 100.

Also note that in either case the last line shown above is only output once (not twice as requested) because that line only appears in the input once.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

TCL script to print range of lines between patterns

Hi I am having a code as stated below module abcd( a , b , c ,da , fa, na , ta , ma , ra , ta, la , pa ); input a , b, da ,fa , na , ta , ma; output c , ra ,ta , la ,pa ; wire a , b , da , fa ,na , ta , ma; endmodule I need to match the string... (1 Reply)
Discussion started by: kshitij
1 Replies

2. Shell Programming and Scripting

perl script print the lines between two pattern

i have a file as below sample.pl parameter1 argument1 argument2 parameter2 I want out as below argument1 argument2 that is , i want to print all the lines between parameter1 & parameter 2. i tried with the following if($mystring =~ m/parameter1(.*?)parameter2/) (2 Replies)
Discussion started by: roopa
2 Replies

3. Shell Programming and Scripting

Help with script to read lines from file and count values

Hi, I need some help with a script I'm trying to write. I have a log file containing references to a number of different webservices. I wish to write a script that will list the webservices with a count as to how many times they appear in the log. An example of the log file content: ... (2 Replies)
Discussion started by: gman2010
2 Replies

4. Shell Programming and Scripting

Why does my script only read two lines of a file and not the third

I'm learning about the read command and wrote this little script to read data from a file: readfile() { while read variable; do echo $variable done } readfile < File.txt I have three lines in File.txt; each a single word. The script only echoes the first two lines and drops the... (9 Replies)
Discussion started by: Straitsfan
9 Replies

5. Shell Programming and Scripting

script to read the contents of a file and print

Hi, Need help in writing a script to read the contents of this file test Test 00a 00b 00c 00d 00e 00f where it need to read each line to give a display such as form meta from dev 00a , config=Striped; add dev 00b:00f to meta 00a Can any one help me in writing this script (2 Replies)
Discussion started by: praveen1516
2 Replies

6. Shell Programming and Scripting

print lines AFTER lines cointaining a regexp (or print every first and fourth line)

Hi all, This should be very easy but I can't figure it out... I have a file that looks like this: @SRR057408.1 FW8Y5CK02R652T length=34 AGCAGTGGTATCAACGCAGAGTAAGCAGTGGTAT +SRR057408.1 FW8Y5CK02R652T length=34 FIIHFF6666?=:88@@@BBD:::?@ABBAAA>8 @SRR057408.2 FW8Y5CK02TBMHV length=52... (1 Reply)
Discussion started by: kmkocot
1 Replies

7. Shell Programming and Scripting

read file-print lines in sed

Hello! Im trying to read file contents. Then, print out every line that has "/bens/here" in the file that was read. cat /my/file.now | sed '/bens/here/p' I keep getting the error asking if I need to predeclare sed? What does predeclaring sed mean? Thanks! Ben (2 Replies)
Discussion started by: bigben1220
2 Replies

8. Shell Programming and Scripting

help using read in menu script to cat out lines in logs

What is wrong with my menu script? Do I need to continue with the read statements? All I want to do with option 4 is to cat some /var/log/files and awk out a few lines? How do I do that please? $ cat menu.sh ... (11 Replies)
Discussion started by: taekwondo
11 Replies

9. Shell Programming and Scripting

Help!! Need script to read files and add values by lines...

Hi All, I really need your help. I am a begginner in shell script and I believe this is a very simple issue. I have in my directory, n-files, like 1.dhm, 2.dhm, 3.dhm. These files have 1 column with 1 value per line, like: 1.dhm ------ 10 20 30 40 50 2.dhm ------ 30 50 20 (3 Replies)
Discussion started by: dhuertas
3 Replies

10. Shell Programming and Scripting

Shell Script to read specific lines in a file

I have a file with contents as follows Record 1: Rejected - Error on table "DWO"."P2G_CUST_EVENTS". ORA-00001: unique constraint (DWO.CUST_EVENTS_PK) violated Record 5: Rejected - Error on table "DWO"."P2G_CUST_EVENTS". ORA-00001: unique constraint (DWO.CUST_EVENTS_PK) violated Record 6:... (5 Replies)
Discussion started by: varshanswamy
5 Replies
Login or Register to Ask a Question