Sponsored Content
Top Forums Shell Programming and Scripting Problem with IF condition in awk Post 302147408 by ashikin_8119 on Tuesday 27th of November 2007 01:08:32 AM
Old 11-27-2007
Problem with IF condition in awk

Hi all;

I'm stuck with this simple awk script,i need to group the lines which the position of 28 length 3 that contains "688" into 1 group and other than "688" into another group. My problem is the script only read other than "688" and ignores the lines which contains "688".

The file look like this:
040171011140820070000000009650244002933170003000000075272
1F921338300506 01082007000688jkjddiwe02499834fg
1F921338300506 010820070000198676767675645shdjd
1H912279980109 0108200700009965787889890090uyk
1H912279980109 01082007000688djjdfieuireurireiro

I used this script to group the lines:
Quote:
sort -t" " -rk2.12,2.14 FileLoad.txt |awk '
/^1/ { sub(/1/, "2") }
/^3/ { saved = $0 }
/^0/ { $NF = ($NF FS saved) }
{ x[FNR] = $0 }
END{
if (substr(x[FNR],1,1)=="0")
print x[FNR]


if(substr(x[j],1,1)!="0" && substr(x[j],28,3)=="688")
{
print 1
for (j=1; j<=FNR; j++)
if(substr(x[j],1,1)!="0" && substr(x[j],28,3)=="688")
print x[j]
}


if(substr(x[j],1,1)!="0" && substr(x[j],28,3)!="688")
{
print 1
for (j=1; j<=FNR; j++)
if(substr(x[j],1,1)!="0" && substr(x[j],28,3)!="688")
print x[j]
}
}'
After execute the script,the output shown:
040171011140820070000000009650244002933170003000000075272
1
2H912279980109 0108200700009965787889890090uyk
2F921338300506 010820070000198676767675645shdjd


can anyone help me to figure out?tq in advance

Last edited by ashikin_8119; 11-27-2007 at 07:49 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

problem in if condition

hi, actully i need the belp for the below. host_list=" Host1 host2 host3 host4 " n=`hostname` i need to put the condition like the below if n is among the host mention in the host_list if then #some stugg else # some other stuff fi (1 Reply)
Discussion started by: mail2sant
1 Replies

2. Shell Programming and Scripting

problem in if then else condition

Hi , I am trying the following simple script . But it is always giving 1 output. Dont know why #!/bin/sh find . -name "a.log" if ; then echo "1" else echo "0" fi Kindly advice. it is giving 1 output even when the a.log file is not there (26 Replies)
Discussion started by: himvat
26 Replies

3. Shell Programming and Scripting

Problem in using AND OR condition together

a=rhino b=crocodil c=testsc if && "$c" = testsc ] then echo "Test #5 succeeds." else echo "Test #5 fails." fi i need to test or condition before check the output with AND condition. ur help is much appreciated... (11 Replies)
Discussion started by: gokulraj23
11 Replies

4. Shell Programming and Scripting

Problem in if condition

Hi all, I have task to delete two different files from all file system. one is core file & other is old file. i can delete core file but for old file i have to mv in different location. i wrote a script but it is not working. i have a two variables in this script first one is delcnt &... (6 Replies)
Discussion started by: dravi_laxmi
6 Replies

5. Shell Programming and Scripting

problem with if condition

Hi, I'm writing a bash script and i have a condition that goes if then break fi but, when i go to run it, i come across this line 10: ' where line 10 is the if I don't know what's going on :( (2 Replies)
Discussion started by: channyboy
2 Replies

6. Shell Programming and Scripting

Problem in if condition

Hi, below is the script in ksh and i am having issues with if condition. It takes in one argument as input and executes the shell script. The problem is in if condition in shell script. If input is given as 1 it works out well. But if input is given as 2 or something else the script is failing to... (1 Reply)
Discussion started by: abhi_123
1 Replies

7. Shell Programming and Scripting

Problem using shell variable in awk if condition

Hi friends, I'm having a bit of a problem using shell variable in an awk if statement. Please note that i'm using -v option as listed in many forums but I still don't get it working. Here's my code. Kindly help as I've gone crazy trying to work this out :wall: #!/bin/bash -xv ... (4 Replies)
Discussion started by: vishwas.s
4 Replies

8. 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

9. Shell Programming and Scripting

Condition problem

Hi All, Seeking for your assistance on how to condition it correctly. cat file1.txt 290,1663,43,888,0,0.00,86.91,0.00,26.98,0.00 290,1663,52,0,0,0.00,0.00,0.00,0.00,0.00 290,1663,52,888,0,0.00,34.60,0.00,9.00,0.00 1st scenario: if the fourth column contains 888s and 0s it is by... (16 Replies)
Discussion started by: znesotomayor
16 Replies

10. UNIX for Beginners Questions & Answers

Problem with getting awk to multiply a field by a value set based on condition of another field

Hi, So awk is driving me crazy on this one. I have searched everywhere and read man, docs and every related post Google can find and still no luck. The actual files I need to run this on are sensitive in nature, but it is the same thing as if I needed to calculate weighted grades for multiple... (15 Replies)
Discussion started by: cotilloe
15 Replies
seteuid(2)							System Calls Manual							seteuid(2)

NAME
seteuid(), setegid() - set effective user and group IDs SYNOPSIS
DESCRIPTION
sets the effective user ID of the calling process, if euid is equal to the current real or saved user ID, or if the process has appropriate privileges. The real user ID and saved set-user-ID remain unchanged. sets the effective group ID of the calling process, if egid is equal to the current real or saved group ID, or if the process has appropri- ate privileges. The real group ID, saved set-group-ID and any supplementary group IDs remain unchanged. RETURN VALUE
Upon successful completion, and return 0; otherwise, they return -1 and set to indicate the error. ERRORS
and fail if any of the following conditions are encountered: euid, or egid, is not a valid user or group ID. The process does not have appropriate privileges and euid/egid does not match the real use/group ID or the saved set-user-ID/set-group-ID. AUTHOR
and were developed by HP. SEE ALSO
exec(2), getegid(2), geteuid(2), getuid(2), setregid(2), setresgid(2), setresuid(2), setreuid(2), setuid(2). STANDARDS CONFORMANCE
seteuid(2)
All times are GMT -4. The time now is 04:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy