- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: script to add an inputted variable in a line
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
Discussions
Discussions
Forums
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
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
тАО02-04-2010 10:01 AM
тАО02-04-2010 10:01 AM
script to add an inputted variable in a line
I know there is a simple answer but I cant put my finger on it,
I simply want to take a file with the fields
NAME1:NAME2:NAME3::::NAME1
Ask the user for input and drop that input before the SECOND NAME1
to have
NAME1:NAME2:NAM3::USERINPUT:NAME1
I was thinking of sed тАУe but I need to drop it between the 2 colons
and not sure if I can?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-04-2010 10:12 AM
тАО02-04-2010 10:12 AM
Re: script to add an inputted variable in a line
# echo "NAME1:NAME2:NAME3::::NAME1" | sed -e 's/::::/::USERINPUT:/'
NAME1:NAME2:NAME3::USERINPUT:NAME1
...matches your apparent requirement.
...but I suspect you want:
# USERINPUT=Scott
# echo "NAME1:NAME2:NAME3::::NAME1" | sed -e "s/::::/::$USERINPUT:/"
NAME1:NAME2:NAME3::Scott:NAME1
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-04-2010 11:37 AM
тАО02-04-2010 11:37 AM
Re: script to add an inputted variable in a line
inputfile=$1
outputfile=$2
exec 3<$inputfile
while read -u3 a
do
echo $a : input?
read b
echo "${a%:*}$b${a##*:}"
done >$outputfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-04-2010 11:47 AM
тАО02-04-2010 11:47 AM
Re: script to add an inputted variable in a line
I got it working, and I am "fine tuning" it more but your help got me over the : i was over thinking it...
I have it working with
read A
read B
grep -i $A filename | sed -e "s/:::/::$B:/"
gets me to to put the file as I need, and I am sure I can simply reverse it to back it out as needed....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-08-2010 05:46 AM
тАО02-08-2010 05:46 AM