Sponsored Content
Top Forums Shell Programming and Scripting Bash script questions for gurus Post 302338580 by mayi on Tuesday 28th of July 2009 10:08:39 AM
Old 07-28-2009
Error Bash script questions for gurus

guys,

I need a steer in the right direction for this issue. it would be great if anyone of you can help me out.

i have a textfile where i want to swap the lines based on the user input.

The textfile is looks like the

#file 1 name
TB
#file 1 ID
1000
#
#file for ID1 system1
AB_12_TB_3000
#
#file for ID1 system2
BC_12_TB_3000
#file 2 name
CO
#file 2 ID
5000
#
#file for ID2 system1
AB_12_CO_3000
#
#file for ID2 system2
BC_12_CO_3000

if the user enters CO then i want CO,5000 and the files should be file 1 and the TB should be file 2. basically interchanging it and making the user entry to be on top and putting the top one to be on the placeholder of file2.here i have mentioned only 2 files, but i am dealing with more than 2 in my files.

The code i have written so far is like this. it works except the ID part.

THE FILENAME IS ROCK.IN i.e that why u see rock.in at the end.

MY QUESTION WOULD BE

1)IS THERE A MORE ROBUST AND EASIER WAY TO DO THIS.

2)MY LAST SED STATEMENT IS NOT CHANGING IT PROPERLY

Code:
#!/bin/bash


user_rock=$(grep -hi 'tb' rock.in)

val=$(grep -A 3 -m 1 -hi 'tb' rock.in)



rock1=$(sed -n -e '/file 1/ {n;p;}' rock.in)


D1=`echo $rock1 | cut -d ' ' -f3`
r_name=`echo $D1| cut -d '_' -f3`

D2=`echo $rock1 | cut -d ' ' -f2`

D3=`echo $val | cut -d ' ' -f5`
D6=`echo $val | cut -d ' ' -f3`

D4=`echo $user_rock | cut -d ' ' -f3`
u_name=`echo $D4| cut -d '_' -f3`

sed -i "s/$u_name/ch/gi" rock.in

sed -i "s/$r_name/$u_name/gi" rock.in

sed -i "s/ch/$r_name/gi" rock.in

sed -i "/file 1 ID/,/{n;p;}/s/$D2/$D3/g" rock.in

sed -i "/file $D6 ID/,/{n;p;}/s/$D3/$D2/g" rock.in


#echo $D3 $D2

exit 0

I WOULD APPRECIATE ANY IDEAS OR SUGGESTIONS. THANKS AGAIN

Last edited by mayi; 07-28-2009 at 12:26 PM.. Reason: code tags
 

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Any RF unix gurus out there?

I am having a problem here. We are having several problems in regards to hung process's on unix (HPUX box), caused by my RF equipment (Mobile data capture units). these contact the host via a simply telnet session and locks the system? Is it a timeout problem as the timeout is disabled on the host. (5 Replies)
Discussion started by: Subrosa
5 Replies

2. Shell Programming and Scripting

bash and Perl interaction questions

hi. i´m working in bash and am trying to create a Perl daemon that controls bash´s behavior. this is actually in preparation for a later project i´ll be working on. basically, i´m looking for a way to have the Perl daemon tell bash what to do. i already have a small daemon that simply prints... (2 Replies)
Discussion started by: deryk
2 Replies

3. Shell Programming and Scripting

Help with shell script - Unix Gurus calling

Unix Gurus, I have been breaking my head to get this done..seems simple.. I need to read a flat file and based on a key word in a line, i need to skip the previous 3 lines. eg : Line1 Line2 Line3 Line4 Line5 Line6 Error Line7 Line8 Line9 Error Line10 (4 Replies)
Discussion started by: ravred
4 Replies

4. Shell Programming and Scripting

SED GURUS - Help!

I wish to substituite a string on each line but ONLY if it appears within double-quotes: this_string="abc#def#geh" # Comment here I wish to change the "#" characters within the double quoted string to "_": this_string="abc_def_geh" # Comment here ... but as you see, the "comment" hash... (2 Replies)
Discussion started by: Simerian
2 Replies

5. Shell Programming and Scripting

Bash Questions

Hello I have to do a program in Bash, need help because it does not go out for me and go enough time with this!! Five directories(boards of directors) that more occupy, arranged according to size. To measure the size of every directory(board of directors) there must not be included the size of... (2 Replies)
Discussion started by: danihj
2 Replies

6. Shell Programming and Scripting

Bash Questions

I am writing a Bash script that needs to get part of the current directory path. Let's say the current directory is /cat/dog/bird/mouse/ant. I know that the part that I want is between "bird/" and "/ant". In this case, I would want to set a variable to "mouse". If the current directory were... (4 Replies)
Discussion started by: RickS
4 Replies

7. Shell Programming and Scripting

Technical questions on bash,mysql and pHp

1. bash -bash escape rules, esp. ',", -how to use Ctrl+R reverse cmd search with regex? 2. mysql -how to use grep in mysql 3. php -why !0 is not evaluated to true? what's its value -php getopt: what if there is duplicate in cmdline args (2 Replies)
Discussion started by: John_Peter
2 Replies

8. Shell Programming and Scripting

Question to gurus with expect

Hi., I need to ask question for expect script. I have prompt like # and very long script (orachk). I added to expect script line set prompt "(%|#|\\\$) $" and insert into it also piece of code ---- expect { timeout { puts "Running..." exp_continue } ... (0 Replies)
Discussion started by: beckss
0 Replies

9. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies
CHECKBASHISMS(1)					      General Commands Manual						  CHECKBASHISMS(1)

NAME
checkbashisms - check for bashisms in /bin/sh scripts SYNOPSIS
checkbashisms script ... checkbashisms --help|--version DESCRIPTION
checkbashisms, based on one of the checks from the lintian system, performs basic checks on /bin/sh shell scripts for the possible presence of bashisms. It takes the names of the shell scripts on the command line, and outputs warnings if possible bashisms are detected. Note that the definition of a bashism in this context roughly equates to "a shell feature that is not required to be supported by POSIX"; this means that some issues flagged may be permitted under optional sections of POSIX, such as XSI or User Portability. In cases where POSIX and Debian Policy disagree, checkbashisms by default allows extensions permitted by Policy but may also provide options for stricter checking. OPTIONS
--help, -h Show a summary of options. --newline, -n Check for "echo -n" usage (non POSIX but required by Debian Policy 10.4.) --posix, -p Check for issues which are non POSIX but required to be supported by Debian Policy 10.4 (implies -n). --force, -f Force each script to be checked, even if it would normally not be (for instance, it has a bash or non POSIX shell shebang or appears to be a shell wrapper). --extra, -x Highlight lines which, whilst they do not contain bashisms, may be useful in determining whether a particular issue is a false posi- tive which may be ignored. For example, the use of "$BASH_ENV" may be preceded by checking whether "$BASH" is set. --version, -v Show version and copyright information. EXIT VALUES
The exit value will be 0 if no possible bashisms or other problems were detected. Otherwise it will be the sum of the following error val- ues: 1 A possible bashism was detected. 2 A file was skipped for some reason, for example, because it was unreadable or not found. The warning message will give details. SEE ALSO
lintian(1). AUTHOR
checkbashisms was originally written as a shell script by Yann Dirson <dirson@debian.org> and rewritten in Perl with many more features by Julian Gilbey <jdg@debian.org>. DEBIAN
Debian Utilities CHECKBASHISMS(1)
All times are GMT -4. The time now is 06:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy