- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: 3rd line of Script modification
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2004 01:10 AM
07-23-2004 01:10 AM
3rd line of Script modification
I need to change the third line of the script such as ...
for instance : 3rd line value is 250,
I need to update the record by 350 and so forth ..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2004 01:25 AM
07-23-2004 01:25 AM
Re: 3rd line of Script modification
use vi ??
Are you saying that you have a script or that you need to write one, that will change the value in some file on line 3 from the value 250 to 350 ??
If you are changing a file(s), then are these files text type files?
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2004 02:05 AM
07-23-2004 02:05 AM
Re: 3rd line of Script modification
use this simple awk script,
-----250.awk---
BEGIN {
FS="\n"
OFS="\n"
RS=""
}
{
gsub ("250","350", $3)
print $0
}
---------
#awk -f 250.awk myfile
regds,
Abdul.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2004 02:32 AM
07-23-2004 02:32 AM
Re: 3rd line of Script modification
I think I was not clear enough .. let me elaborate more in detail ..
I have a master script, that would actually change the content of the sub script(2 file) dynamically, and content of the sub script would be something like this
When I run the Parentscript.sh
child script content will be something like this (childscript.sh)
Content has 3 lines in the script
"125,435
121,test
450"
The value 450(+100) will be changed dynamically to 550 when I run the master script and again I run the master script, the value will be changed to 650 and so forth .. (
In short:
Childscript.sh - Value should be changed dynamically to +100 everytime When I run the master script ........
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2004 03:09 AM
07-23-2004 03:09 AM
Re: 3rd line of Script modification
vi file
:/%s/250/350/ enter
:x #save and quit
if you want script, simply like this:
#!/bin/bash
sed 's/250/350/' file.txt > changed_file.txt
br Jan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2004 06:40 AM
07-24-2004 06:40 AM
Re: 3rd line of Script modification
typeset -i LINENUM=3
typeset -i INCR=100
typeset CHSCR="childscript.sh"
typeset -i i=0
typeset -i x=0
while read inline
do
[[ -n "$inline" || "$inline" = \#* ]] && continue
line[$x]="$inline"
((x += 1))
done < $CHSCR
# convert to a number
i="${line[$LINENUM]}"
((i+=INCR))
line[$LINENUM]="$i"
i=${#line[*]}
x=0
while ((x < i ))
do
echo "${line[$x]}"
((x += 1))
done >$CHSCR
=========================================
I am assuming that your quotes (") in the example are not actually in the childscript.sh file. If they are, you will need to change the "convert" code to:
i="${line[$LINENUM]%\"}"
((i+=INCR))
line[$LINENUM]="$i"\"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2004 10:21 AM
07-24-2004 10:21 AM
Re: 3rd line of Script modification
tmpfile=/tmp/something$$
awk '
NR == 3 {
x=$1+0;
x+=100;
$1=x;
print $0;
next;
}
{print;}' $f1 > $tmpfile
if [ $? = 0 ] ;then
mv $tmpfile $f1
else
print "awk error"
fi