Sponsored Content
Top Forums Shell Programming and Scripting Sed: would like to return an error for empty string Post 303045788 by RudiC on Monday 13th of April 2020 09:17:42 AM
Old 04-13-2020
Try testing for "start-of-line nothing end-of-line":

Code:
echo "" | sed -n -r '/[0-9]{3}/{q100}; /^$/{q200}'; echo $?
200

And, wouldn't it make sense to have different codes for different errors?
This User Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to check for null or empty string

Hi, I need to check for value not equal (<>) to 21 and not equal empty or null values. Please modify this script if then echo "$VALUE,$BSC_NAME,$BSC_ID" > $OUT_FILE/power_up.out end if TQ (5 Replies)
Discussion started by: doer
5 Replies

2. Shell Programming and Scripting

Check for empty string

Hello All, I have written shell script whcih at the max 3 parameters. When only one commandline argument and other two command line arguments are passed as empty string like eg : archive ' ' ' ' Then i need to check whether the commandline... (12 Replies)
Discussion started by: rahman_riyaz
12 Replies

3. UNIX for Dummies Questions & Answers

to check if file is empty or not and return a non zero value

Hi All, I am new to unix worldd . I need to check a file1 if its empty or not. If its empty then return a non zero value say 99 could you pls let me know the perl script for this. (2 Replies)
Discussion started by: mavesum
2 Replies

4. Shell Programming and Scripting

Need Help to deal with empty string

Hi one to All i have written the code for searching the string in the file for specified path. its working fine, but my req:if the string is not available in the file , it should display the Message saying that , string is not available in the file. code is: echo "give the path where... (12 Replies)
Discussion started by: saic
12 Replies

5. Shell Programming and Scripting

error while replacing a string by new line character in sed

hi, when i am doing the following things getting error Can anyone please suggest i have a file where there is a line like the following branch=dev sdf dev jin kilii fin kale boyle dev james dev i want to search the existance of dev in the above line. cat "$file" | sed -n... (8 Replies)
Discussion started by: millan
8 Replies

6. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

7. Programming

Checking not empty string

I have a string s Are the following equivalent? if ( ! s.empty() ) { } if ( s ) { } (1 Reply)
Discussion started by: kristinu
1 Replies

8. Shell Programming and Scripting

Check if the string is empty

I am reading from a file and executing the jobs with/without parameters as the job requires. File job1 R job2 job3 Y 123 if then <job>.ksh else <job>.ksh $params fi This works fine if the line read from the file has parameters it executes like job1.ksh R But for... (2 Replies)
Discussion started by: nw2unx123
2 Replies

9. Shell Programming and Scripting

Unzipping the empty file sends a non Zero return code

Hi, I have a shell script where I am trying to unzip bunch of files zip files one by one. But out of many zip files, if any one zip file is empty, the unzip command sends a non-zero return code and fails the script. I am trying to see if I can get a success error code even if the script... (2 Replies)
Discussion started by: Saanvi1
2 Replies

10. Shell Programming and Scripting

Cant check empty string

Hello So i have that script collection, in which i have a single script to create a configuration file. In there, i have multiple occourences of something like this: prj_title=$(tui-read "What is the TITLE? ($prj_name):") ] && prj_title="${prj_name/_/ }" They all work as expected, if... (5 Replies)
Discussion started by: sea
5 Replies
basename(1)						      General Commands Manual						       basename(1)

NAME
basename, dirname - extract portions of path names SYNOPSIS
string [suffix] [string] DESCRIPTION
deletes any prefix ending in and the suffix (if present in string) from string, and prints the result on the standard output. If string consists entirely of slash characters, string is set to a single slash character. If there are any trailing slash characters in string, they are removed. If the suffix operand is present but not identical to the characters remaining in string, but it is identical to a suf- fix of the characters remaining in string, the suffix is removed from string. is normally used inside command substitution marks within shell procedures. delivers all but the last level of the path name in string. If string does not contain a directory component, returns indicating the cur- rent working directory. EXTERNAL INFLUENCES
Environment Variables determines the interpretation of string and, in the case of basename, suffix as single and/or multi-byte characters. If is not specified in the environment or is set to the empty string, the value of is used as a default for each unspecified or empty vari- able. If is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of If any internationalization variable contains an invalid setting, and behave as if all internationalization variables are set to "C". See environ(5). International Code Set Support Single- and multi-byte character code sets are supported. EXAMPLES
The following shell script, invoked with the argument compiles the named file and moves the output to a file named in the current direc- tory: The following example sets the shell variable to RETURN VALUE
and return one of the following values: Successful completion. Incorrect number of command-line arguments. SEE ALSO
expr(1), sh(1). STANDARDS CONFORMANCE
basename(1)
All times are GMT -4. The time now is 11:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy