Else statement in looking for a character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Else statement in looking for a character
# 1  
Old 11-01-2018
Else statement in looking for a character

I have list of hostnames with
Code:
# cat list
servdc01
servdc02
compdc01
compdc02
servit01
servit02
prindc01
datacenter01
dcenit01
dcendc01
[root]


If the hostname has dc in 5,6. Copy a file dedicated for them,
if the hostname has IT in 5,6. Copy a file dedicated for them.


Code:
dc=`cat list|grep dc`  # I cant do this because it will get this data dcendc01
it= `cat list|grep it`
if [ $dc -ne 0 ]
then
cp /files/intended_for_dc_hosts $dc
fi


if [ $it -ne 0 ]
then
cp /files/intended_for_it_hosts $it
fi
. . .

# 2  
Old 11-01-2018
if you insist on using grep....
Code:
grep -E '^....dc' myFile
grep -E '^....it' myfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to escape the @ character in an if statement check?

Hi, I am running a shell script that has to verify a password with an if statement. The password has an @ in it. I am having problems getting the if statement to test for the password. The @ causes problem. I tried the standard backslash escape but it did not work for me. How can I do it? I... (2 Replies)
Discussion started by: mojoman
2 Replies

2. Shell Programming and Scripting

sed searches a character string for a specified delimiter character, and returns a leading or traili

Hi, Anyone can help using SED searches a character string for a specified delimiter character, and returns a leading or trailing space/blank. Text file : "1"|"ExternalClassDEA519CF5"|"Art1" "2"|"ExternalClass563EA516C"|"Art3" "3"|"ExternalClass305ED16B8"|"Art9" ... ... ... (2 Replies)
Discussion started by: fspalero
2 Replies

3. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

4. Shell Programming and Scripting

Regex escape special character in AWK if statement

I am having issues escaping special characters in my AWK script as follows: for id in `cat file` do grep $id in file2 | awk '\ BEGIN {var=""} \ { if ( /stringwith+'|'+'50'chars/ ) { echo "do this" } else if ( /anotherString/ ) { echo "do that" } else { ... (4 Replies)
Discussion started by: purebc
4 Replies

5. Shell Programming and Scripting

How to remove a defined character on an array variable in a do while statement in ksh

I have a korn shell code here on a while do statement which replace the string stored on an array removing double quotes characters on it but it doesn't work. example record: appointmentDate = "tree" which value should result to tree #!/bin/ksh # Remove " on string records let recordCount=3... (5 Replies)
Discussion started by: ryukishin_17
5 Replies

6. Shell Programming and Scripting

Deleting all characters from 350th character to 450th character from the log file

Hi All, I have a big log file i want to delete all characters (between 350th to 450th characters) starting at 350th character position to 450th character position. please advice or sample code. (6 Replies)
Discussion started by: rajeshorpu
6 Replies

7. Shell Programming and Scripting

read in a file character by character - replace any unknown ASCII characters with spa

Can someone help me to write a script / command to read in a file, character by character, replace any unknown ASCII characters with space. then write out the file to a new filename/ Thanks! (1 Reply)
Discussion started by: raghav525
1 Replies

8. Shell Programming and Scripting

How is use sselect statement o/p in insert statement.

Hi All, I am using Unix ksh script. I need to insert values to a table using the o/p from a slelect statement. Can anybody Help! My script looks like tihs. ---`sqlplus -s username/password@SID << EOF set heading off set feedback off set pages 0 insert into ${TB_NAME}_D... (2 Replies)
Discussion started by: nkosaraju
2 Replies

9. Shell Programming and Scripting

How do I ignore one character in a case statement? PLEASE HELP!

Hello, I am new to this forums. I need help with shell, and ksh in particular. I have a case statement that does something if -k. So it looks like: case $arg in -k) PUT=y, SEND=1 Thats all good and dandy. But now I want to change it where whether or not the user puts -k or not, it will do... (2 Replies)
Discussion started by: cpunisher
2 Replies

10. Shell Programming and Scripting

If statement - How to write a null statement

In my ksh script, if the conditions of a if statement are true, then do nothing; otherwise, execute some commands. How do I write the "do nothing" statement in the following example? Example: if (( "$x"="1" && "$y"="a" && "$z"="happy" )) then do nothing else command command fi... (3 Replies)
Discussion started by: april
3 Replies
Login or Register to Ask a Question