- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- need to insert a / in a word multiple times - scri...
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
10-20-2005 07:46 AM
10-20-2005 07:46 AM
Each line is (in all essence) one word.
I need to insert a / after the:
2nd character
6th
12th
15th
and 19th character
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2005 08:02 AM
10-20-2005 08:02 AM
Re: need to insert a / in a word multiple times - script
cat FILE | while read LINE
do
F1=`echo $LINE | cut -c1-2`
F2=`echo $LINE | cut -c3-6`
...
echo "${F1}/${F2}......." > NEWFILE
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2005 08:14 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2005 08:16 AM
10-20-2005 08:16 AM
Re: need to insert a / in a word multiple times - script
perl -n -e 'print join("/",unpack("a2a4a6a3a4a999",$_))'
PS-
To write the data back to the original file, do-
perl -i -p -e 'print join("/",unpack("a2a4a6a3a4a999",$_))' yourfile
Of course "yourfile" can be replaced with a wildcard name to do multiple files.
Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2005 08:19 AM
10-20-2005 08:19 AM
Re: need to insert a / in a word multiple times - script
cat $INFILE | awk '
BEGIN { FS = " " }
{ F1=substr($1,1,2)
F2=substr($1,3,6)
F3=substr($1,7,12)
...
F4=
F5
}
{ printf F1 }
{ printf "/" }
{ printf F2 }
...
{ printf F5 }
{ printf "\n" }
}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2005 08:47 PM
10-20-2005 08:47 PM
Re: need to insert a / in a word multiple times - script
you can use:
echo "$(cut -c 1-2 f)/$(cut -c 3-6 f)/$(cut -c 7-12 f)/$(cut -c 13-15 f)/$(cut -c 16-19)/"
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2005 09:01 PM
10-20-2005 09:01 PM
Re: need to insert a / in a word multiple times - script
# echo "123456789abcdefghij12" | wc -c
22
# echo "123456789abcdefghij12" | sed 's%^\(.\{2\}\)\(.\{4\}\)\(.\{6\}\)\(.\{3\}\)\(.\{4\}\)\(.*\)%\1/\2/\3/\4/\5/\6%g'
12/3456/789abc/def/ghij/12
# perl -pi -e '
will update automatically.
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2005 09:06 PM
10-20-2005 09:06 PM
Re: need to insert a / in a word multiple times - script
# cat > file
hibyehibyehobyehibyeokok
okokokokokokokokokokokok
# perl -pe 's%^(.{2})(.{4})(.{6})(.{3})(.{4})(.*)%\1/\2/\3/\4/\5/\6%g' file
hi/byeh/ibyeho/bye/hiby/eokok
ok/okok/okokok/oko/koko/kokok
# perl -pi -e 's%^(.{2})(.{4})(.{6})(.{3})(.{4})(.*)%\1/\2/\3/\4/\5/\6%g' file
# cat file
hi/byeh/ibyeho/bye/hiby/eokok
ok/okok/okokok/oko/koko/kokok
#
-Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2005 02:57 AM
10-21-2005 02:57 AM
Re: need to insert a / in a word multiple times - script
Create a file containing the following:
#!/usr/dt/bin/dtksh
for X in $(<${1:-/dev/null});do
echo "${X:0:2}/${X:2:4}/${X:6:6}/${X:12:3}/${X:15:4}/${X:19}"
done
Call it 'myscript.sh' for example.
Run it using 'myscript.sh
Where 'filename' is the name of the file you want to process.
Adam Harvey
PS: The weirdness involving /dev/null prevents the script hanging if you do not supply a file-name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2005 04:18 AM
10-21-2005 04:18 AM
Re: need to insert a / in a word multiple times - script
awk '{printf("%2s/%4s/%6s/%3s/%4s/%s \n",substr($1,1,2),substr($1,3,4),substr($1,7,6),substr($1,13,3),substr($1,16,4),substr($1,20))}' < useme
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2005 09:30 AM
10-21-2005 09:30 AM