Sponsored Content
Top Forums Shell Programming and Scripting Logic needed to recursive looping in the script Post 302543120 by dsdev_123 on Friday 29th of July 2011 03:24:03 PM
Old 07-29-2011
Quote:
Originally Posted by panyam
Code:
awk 'NR==FNR&&length($1)>=6{a[$1]} 
     NR>FNR{if (length($1)<6) { new=substr($1 "XXXXX",1,6);
                          while (new in a) {i++;new=substr($1 "XXXXXXXXXXXXXXXXX",1,6+i)}
                          a[new];print $1,$1","new;i=0
                        }
      else{print $1,$1","$1}
     }' input_file input_file

sorry to ask this again
in the input file i have 2 columns and the logic should be applied on col2 and the 2 columns are separated by comma in the input file.The outfile should have 2 columns in the file and 3rd derived column separated by comma.






Code:
input file
outputfile
1,ABC
1,ABC, ABCXXXX
2,ABCD
2,ABCD,ABCDXXXXX
3,ABCDX
3,ABCDX,ABCDXXXXXX
4,ABCDXX
4,ABCDXX,ABCDXX
5,ABCDXXX
5,ABCDXXX,ABCDXXX
6,ABCDXXXX
6,ABCDXXXX,ABCDXXXX
7,ABCXXX
7,ABCXXX,ABCXXX
8,A
8,A,AXXXXX
9,B
9,B,BXXXXX


Thanks again
dsdev

Last edited by dsdev_123; 07-29-2011 at 04:30 PM.. Reason: Code tags.
 

6 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

logic needed to extract lines

Hi All, Are there any logic to extract the only lines between first two *TM* (which is marked in blue)? VOL1HST99 0 HDR1A999999S 999999HST99 HDR2F001200012001 UHL1 0729609000001 000000 *TM*^^^^^^^^^^^^^^^^^^^^^^ 01012610252171017301805000... (2 Replies)
Discussion started by: ganapati
2 Replies

2. Shell Programming and Scripting

Recursive looping through files and directories

hi; i need a script which will go to all directories and subdirectories and print the filenames as follow; here i m printing only files listing in current directory reason i m doing this is coz i want to perform some operations according to filename achieved so cant use find command;... (4 Replies)
Discussion started by: ajaypadvi
4 Replies

3. Shell Programming and Scripting

Logic needed

input : employee_id, salary ------------------- 10, 1000 20, 2000 30, 3000 40, 5000 output: employee_id, salary, next_row_salary ------------------------------------ 10, 1000, 2000 20, 2000, 3000 30, 3000, ... (3 Replies)
Discussion started by: HemaV
3 Replies

4. UNIX for Dummies Questions & Answers

Help needed - find command for recursive search

Hi All I have a requirement to find the file that are most latest to be modified in each directory. Can somebody help with the command please? E.g of the problem. The directory A is having sub directory which are having subdirectory an so on. I need a command which will find the... (2 Replies)
Discussion started by: sudeep.id
2 Replies

5. UNIX for Dummies Questions & Answers

Looping Logic, Need to implement

I need to implement a looping logic. If then Go to /path1/file* Get all the filename starting with file* and store it in a array count file number and store it in variable like run Ex: I found 3 file with starting file* so my run = 3 means my loop should run three time May be... (1 Reply)
Discussion started by: Nsharma3006
1 Replies

6. Programming

Missing Logic Looping Through Switch Statement

Having trouble with the logic when looping over this switch case again: for (j = 0; data != 0; j++){ switch(data){ case 'c': output = ranit(r_brace_array); break; case 'h': output = ranit(pipe_array); break; ... (6 Replies)
Discussion started by: Azrael
6 Replies
escape(1)							Mail Avenger 0.8.3							 escape(1)

NAME
escape - escape shell special characters in a string SYNOPSIS
escape string DESCRIPTION
escape prepends a "" character to all shell special characters in string, making it safe to compose a shell command with the result. EXAMPLES
The following is a contrived example showing how one can unintentionally end up executing the contents of a string: $ var='; echo gotcha!' $ eval echo hi $var hi gotcha! $ Using escape, one can avoid executing the contents of $var: $ eval echo hi `escape "$var"` hi ; echo gotcha! $ A less contrived example is passing arguments to Mail Avenger bodytest commands containing possibly unsafe environment variables. For example, you might write a hypothetical reject_bcc script to reject mail not explicitly addressed to the recipient: #!/bin/sh formail -x to -x cc -x resent-to -x resent-cc | fgrep "$1" > /dev/null && exit 0 echo "<$1>.. address does not accept blind carbon copies" exit 100 To invoke this script, passing it the recipient address as an argument, you would need to put the following in your Mail Avenger rcpt script: bodytest reject_bcc `escape "$RECIPIENT"` SEE ALSO
avenger(1), The Mail Avenger home page: <http://www.mailavenger.org/>. BUGS
escape is designed for the Bourne shell, which is what Mail Avenger scripts use. escape might or might not work with other shells. AUTHOR
David Mazieres Mail Avenger 0.8.3 2012-04-05 escape(1)
All times are GMT -4. The time now is 05:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy