Sponsored Content
Full Discussion: Condition check using awk
Top Forums UNIX for Dummies Questions & Answers Condition check using awk Post 302754429 by nua7 on Thursday 10th of January 2013 02:54:33 PM
Old 01-10-2013
Condition check using awk

Hi,
I have a file in the following format

Code:
"SYLVESTER,WILLARD G"|"S00633600"|"221052958A"|"H2256"|"015"|""|"00000042BASJ"|"665303"|"N"|"20100211"|"380.4"|""|""|""|"5400"|"20110218"|""|"20110218"|"FEESC"|"D"|"F"|"P"
"PURINGTON-KELLEY,C"|"S00808783"|"029424717A"|"H2256"|"024"|"MEMBER JOINED ANOTHER MEDICARE RISK PLAN"|"00000049BAQS"|"SS2323"|"Y"|"20100218"|"728.87"|"782.0"|""|""|"6040"|"20110218"|""|"20110218"|"FEESC"|"D"|"F"|"P"

I need to check if first two characters of the 8th column start with SS. If they start with SS , replace the 8th column by "MEMBER" else replace the 8th column by "PROVIDER"

Desired output :
Code:
"SYLVESTER,WILLARD G"|"S00633600"|"221052958A"|"H2256"|"015"|""|"00000042BASJ"|"PROVIDER"|"N"|"20100211"|"380.4"|""|""|""|"5400"|"20110218"|""|"20110218"|"FEESC"|"D"|"F"|"P"
"PURINGTON-KELLEY,C"|"S00808783"|"029424717A"|"H2256"|"024"|"MEMBER JOINED ANOTHER MEDICARE RISK PLAN"|"00000049BAQS"|"MEMBER"|"Y"|"20100218"|"728.87"|"782.0"|""|""|"6040"|"20110218"|""|"20110218"|"FEESC"|"D"|"F"|"P"

This is something I tried using awk but not sure how to specify the column name

search=SS
replace=member

awk -v srch="$search" -v repl="$replace" '{ sub(srch,repl,$0); print $0 }' newfile


Can someone please help
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with shell script to check the condition.

:) Hi, I want to script for this scenerio, OSR Settings Scenario : We are looking to find all the *.a files from the following locations in the filesystem of a server. OSR Directories /etc /bin /usr/bin /usr/sbin /var/adm These *.a files should have the permissions on... (12 Replies)
Discussion started by: sakthilinux
12 Replies

2. Shell Programming and Scripting

WHILE LOOP CONDITION CHECK

Hello I want to compare values of two variables as CHECK condition in a while loop. eg: var1=0 var2=10 while do echo " $var1 " var1=`expr $var1 + 1` done However this is giving error.How to do it in a proper manner? Thanks. (3 Replies)
Discussion started by: dashing201
3 Replies

3. Shell Programming and Scripting

Check condition inside the loop

Hi, I am in trouble. I can get inside my condition test inside a loop : I am in ksh (solaris) while read file do <commande to retrieve file> >> ${LOG_RETRIEVE_FILE.log} msg_err=$(cat ${LOG_RETRIEVE_FILE.log} | grep "error retrieve") if ; then <sendmail> exit 1 fi done I tried... (6 Replies)
Discussion started by: Aswex
6 Replies

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

5. Shell Programming and Scripting

sed to check two condition need solution

Hi, I am having a file in below format server-1 Win2008:server-1-1700,1774,290104720,290104987:server-1 server-2 AIX:server-2-:server-2 server-2 I want the output like this Win2008:server-1-1700,1774,290104720,290104987:standalon-server AIX:server-2-:VIO-Sever I used the... (7 Replies)
Discussion started by: ranjancom2000
7 Replies

6. Shell Programming and Scripting

if condition to check the hostname (unix)

I want to know the if condition in checking the hostname in unix and then running a cron job (all in a single line) Thanks (2 Replies)
Discussion started by: prash358
2 Replies

7. Shell Programming and Scripting

Check the value in xml based on condition

Hi, I have a log file having n number of xml's like the one below. <uOStatus xmlns:env="http://abc.org/def/ghi/"... (3 Replies)
Discussion started by: Neethu
3 Replies

8. Shell Programming and Scripting

Need to check a condition using SFTP command

HI, I connected to a remote FTP server using sftp command. Need to check if any files are present inside a folder in server directory and then remove if present. The code should look like this How can this condition be written. Thanks in advance, (2 Replies)
Discussion started by: confused_info
2 Replies

9. Shell Programming and Scripting

Check two condition in while loop

Hi, I Have to check two condition in while loop every 2 minutes. while loop is accompanied with number of times it will check.Please help in putting the two condition in while loop as appropriate. z= input value, A=1 while do 1.check the file output,if the file output is N then keep on... (2 Replies)
Discussion started by: netdbaind
2 Replies
STR_IREPLACE(3) 							 1							   STR_IREPLACE(3)

str_ireplace - Case-insensitive version ofstr_replace(3).

SYNOPSIS
mixed str_ireplace (mixed $search, mixed $replace, mixed $subject, [int &$count]) DESCRIPTION
This function returns a string or an array with all occurrences of $search in $subject (ignoring case) replaced with the given $replace value. If you don't need fancy replacing rules, you should generally use this function instead of preg_replace(3) with the i modifier. PARAMETERS
If $search and $replace are arrays, then str_ireplace(3) takes a value from each array and uses them to search and replace on $subject. If $replace has fewer values than $search, then an empty string is used for the rest of replacement values. If $search is an array and $replace is a string, then this replacement string is used for every value of $search. The converse would not make sense, though. If $search or $replace are arrays, their elements are processed first to last. o $search - The value being searched for, otherwise known as the needle. An array may be used to designate multiple needles. o $replace - The replacement value that replaces found $search values. An array may be used to designate multiple replacements. o $subject - The string or array being searched and replaced on, otherwise known as the haystack. If $subject is an array, then the search and replace is performed with every entry of $subject, and the return value is an array as well. o $count - If passed, this will be set to the number of replacements performed. RETURN VALUES
Returns a string or an array of replacements. EXAMPLES
Example #1 str_ireplace(3) example <?php $bodytag = str_ireplace("%body%", "black", "<body text=%BODY%>"); ?> NOTES
Note This function is binary-safe. Caution Replacement order gotcha Because str_ireplace(3) replaces left to right, it might replace a previously inserted value when doing multiple replacements. Example #2 in the str_replace(3) documentation demonstrates how this may affect you in practice. SEE ALSO
str_replace(3), preg_replace(3), strtr(3). PHP Documentation Group STR_IREPLACE(3)
All times are GMT -4. The time now is 07:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy