Visit Our UNIX and Linux User Community


create separate file after checking condition..


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting create separate file after checking condition..
# 1  
Old 04-12-2011
create separate file after checking condition..

Problem :
I want to create a separate file for country list if condition is true. Please help.
*****************************************************
Input file:
Code:
SV-INCR-139302-365540488-201104090934.sqllog
SV-INCR-1082-552793184-201104040805.sqllog
SV-INCR-1077-855045741-201104040805.sqllog
SV-INCR-994-386000426-201104080808.sqllog
*****************************************************

Script :
Code:
#!/bin/ksh
# with the help of awk command we are taking third value.
awk -F'-' '{print $3}' input|while read third; do
# checking if country code is 139302
if [ $third -eq 139302 ] || [ $third -eq 994 ]; then
   echo $third
fi
   done

*****************************************************
output country list file:
Code:
SV-INCR-139302-365540488-201104090934.sqllog
SV-INCR-994-386000426-201104080808.sqllog


Last edited by Franklin52; 04-12-2011 at 05:15 AM.. Reason: Please use code tags
# 2  
Old 04-12-2011
Is that what you need?

Code:
$ awk -F- '$3 == 139302 || $3 == 994' inputfile
SV-INCR-139302-365540488-201104090934.sqllog
SV-INCR-994-386000426-201104080808.sqllog

This User Gave Thanks to hergp For This Post:
# 3  
Old 04-12-2011
thanks hergp.. command is working file but i want to create two seprate file
1. one condition is true.
2. second condition is not true.

---------- Post updated at 02:43 PM ---------- Previous update was at 01:35 PM ----------

i solved my problem.

awk -F- '$3 == 1393awk -F- '$3 == 139302 || $3 == 994' inputfile > conditiontrue
comm -23 inputfile conditiontrue > conditionfalse

Last edited by humaemo; 04-12-2011 at 05:40 AM..
# 4  
Old 04-12-2011
Code:
awk -F- '$3 == 139302 || $3 == 994{print > "conditiontrue";next}1' inputfile > conditionfalse

This User Gave Thanks to Franklin52 For This Post:
# 5  
Old 04-12-2011
wow its nice Franklin52

Previous Thread | Next Thread
Test Your Knowledge in Computers #588
Difficulty: Easy
A linear search algorithm is also known as sequential search.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Create a file on UNIX with multiple columns on certain condition

I need to write the list of files to a new file in one column , the second column would contain the first line of that file (header record extracted through head -1 ) and the third column would contain the last record of that file (trailer record tail -1 ) . Example :- folder where the files... (8 Replies)
Discussion started by: IshuGupta
8 Replies

2. Shell Programming and Scripting

Condition checking issue while if

hi, i am using a simple condition end_ct=`sqlplus -s $ORACLE_USER/$ORACLE_PASS@$ORACLE_SID << EOF select description from bravo_statistics where trunc(time_stamp)=trunc(sysdate)-1 and description='END CAT'; EOF` echo $end_ct; echo... (30 Replies)
Discussion started by: lovelysethii
30 Replies

3. Shell Programming and Scripting

Condition checking in UNIX

i have a script where i have to find the age of a file, if then echo "dnb file is present for the monthly load" >> $RUNLOG dnb="1" else echo "dnb file has not arrived yet" > $ERRLOG dnb="0" fi i know the file is available so... (3 Replies)
Discussion started by: lovelysethii
3 Replies

4. Shell Programming and Scripting

create separate files from one excel file with multiple sheets

Hi, I have one requirement, create separate files (".csv") from one excel file(xlsx) with multiple sheets. These ".csv" files are my source files. So anybody please suggest me the process. Thanks in Advance. Regards, Harris (3 Replies)
Discussion started by: harris
3 Replies

5. Shell Programming and Scripting

Checking file existence along with condition

Hi am trying to write a script which find the existence of a file from a find command output and perform a task if the file exists. Help me out with the correct syntax . Am trying with the following one but unable to get the output. if then <some tasks> else echo "file not exists" fi (5 Replies)
Discussion started by: rogerben
5 Replies

6. Shell Programming and Scripting

How to create a CSV File by reading fields from separate files

SHELL SCRIPT Hi, I have 3 separate files within a folder. Every File contains data in a single column like File1 contains data mayank sushant dheeraj File2 contains DSA_AT MG_AT FLAT_09 File3 contains data 123123 232323 (2 Replies)
Discussion started by: mayanksargoch
2 Replies

7. Shell Programming and Scripting

Cutting specific line of a file by checking condition

testfile.csv 0","1125209",,"689202CBx18888",,"49",,,"NONMC",,,,,"01112010",,,,,,,"MTM- "1","",,"689202ABx19005",,"49",,,"NONMC",,,,,"01072010",,,,,,,"MTM- testfile.csv looks like above format if the second column is null then get 23rd column and store in a different varible .. add all the... (1 Reply)
Discussion started by: mgant
1 Replies

8. Shell Programming and Scripting

Unzip file By checking condition.

Hi.. Gurus I Have a list of .zip files in a directory. I want to check whether each .zip file having some particular file or not (say .jsp) if it's having .Jsp file then create a directory as per the .zip file and extract the content to that directory except the .jsp file, If .zip not having... (3 Replies)
Discussion started by: posix
3 Replies

9. Shell Programming and Scripting

sed solution for condition checking

Hi all , Recently i came across this in FAQ's. I have a file cat rem.txt sreedhar 20 sreedhar 10 sreedhar 15 sreedhar 18 sreedhar 16 sreedhar 30 I have to replace sreedhar with "Sridhar" if the second parameter is > 18. I need to do it in "sed" only. I am wondering how this... (4 Replies)
Discussion started by: panyam
4 Replies

10. Shell Programming and Scripting

Condition checking

Dear all That's another problem from me, i wanna do a lot of if statement checking for correct input by user, will be prompt input again if the input not meet the requirement defined by If or while statement... like this one .... while I know it's less effiency write the program... (14 Replies)
Discussion started by: trynew
14 Replies

Featured Tech Videos