File validation prior to continuing script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers File validation prior to continuing script
# 1  
Old 01-13-2015
File validation prior to continuing script

Hi Guys,
I am trying to find a way within a bash script to check a file that exists in the same directory to ensure every line starts with 44 and is 12 digits long. If it doesn't then print some sort of text advising of the error and stop the script from going any further. If all lines start with 44 and are 12 digits long then continue with the script. Im fairly new to this so any help would really be appreacited.

Thanks
# 2  
Old 01-13-2015
Proposal:
Code:
if grep -nv '^44[0-9]\{10\}$' filename
then
 echo 'Please check the above line(s).'
 exit
fi
echo ...


Last edited by MadeInGermany; 01-13-2015 at 06:53 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Reverse prior batch job (without simply rewriting the script)

So, let's say I have a usual batch rename file like this: and I'd like to have a secon bat file, that can /reverse" the first. BUT, I don't want to simply "rewrite" it like move hello 254352426 but rather, have the new script take the source and destination and reverse it somehow... (6 Replies)
Discussion started by: pasc
6 Replies

2. Shell Programming and Scripting

How to get script to wait until status is true before continuing?

I'm extremely new to shell scripting so I apologize for the crudeness of my descriptions. I am editing a script that will write files (e.g. Job0_A.com, Job1_A.com, etc.) and then run them through a program called gaussian (computational chemistry program). The script will then take the output files... (10 Replies)
Discussion started by: butson
10 Replies

3. Shell Programming and Scripting

Removing all lines prior to the last pattern in a file/stream

Hi all, I didn't find anything that specifically answers this after searching for a bit, so please forgive me if this has been covered before. I'm looking to delete all lines prior to the last occurrence of a string in a file or stream from within a shell script (bash.) A bit of... (4 Replies)
Discussion started by: LivinFree
4 Replies

4. Shell Programming and Scripting

Need to check file space requirements prior to operation

I'm all done with a script that relocates some files from different directories to another, just one caveat; I need it to check if i have enough space to complete the operation. On my commandline i normally use df -h /dir/im/checking | awk '{print $4}' | grep -v Avail I'd like to have my script... (3 Replies)
Discussion started by: DC Slick
3 Replies

5. Shell Programming and Scripting

script to retrieve file for prior day

Is there a way to Create file name for the prior Sunday of the run_date if my Run_date =05262009, i need to the file with the File name= filename.Y20090524.zip Thanks in advance (1 Reply)
Discussion started by: aronmelon
1 Replies

6. UNIX for Advanced & Expert Users

File disk utilization for 10 days prior

Hi I have a requirement to list the files & the total disk utilization they have which are 10 prior to current date. I tried couple of options in combinations of find mtime, ctime with du -m, but no luck. Could you please help me in this ? (2 Replies)
Discussion started by: videsh77
2 Replies

7. Shell Programming and Scripting

Test File Reading & Validation using Shell script

Please help develop script for below requirement -------Sample file------------------------------- HSVSHOSTRECON 20090115011817BP DARMAR60064966247003504720000000000000000000066626000000000000133000003D003463001332 ... (14 Replies)
Discussion started by: niraj_bhatt
14 Replies

8. Shell Programming and Scripting

Identifying prior date in shell script

Hi guys, I'm a newbie to shell script. I have to write a shell script that is supposed to give me a date which should be older than the current date when I supply "no. of days" as a command line parameter to the script. (i.e)., if I am giving the no. of days value as 305, the script should... (5 Replies)
Discussion started by: royalibrahim
5 Replies

9. Shell Programming and Scripting

make sure logged in as userx before continuing script

i have a bash script and I want to add to the begining of the script to make sure that the script is being ran as you are logged in as a certain user (userx) before continuing to run the script....how? (2 Replies)
Discussion started by: ajp7701
2 Replies

10. Shell Programming and Scripting

Need help in file validation by shell script

Hi I am new to this forum.I need a help in the following: We receve pipe delimited file with transaction ID,tran_date,Quest_cd,Ans_cd,ans_value. Same transaction ID can be repeated with different quest_cd and ans_cd. Basically I need to check if a perticular pair of quest_cd and ans_cd... (1 Reply)
Discussion started by: srichakra
1 Replies
Login or Register to Ask a Question