- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: data manipulation in the file
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
тАО03-13-2007 01:07 AM
тАО03-13-2007 01:07 AM
Re: data manipulation in the file
>>
since i dont understand perl.
<<
That does not matter, IMHO: There may be solutions in other languages, you won't understand, as well.
We do not have your answer yet: Is the change of these characters required once in that file or in every line of it?
More questions:
- What about lines with less than 7 characters?
- Will newline charactes count?
All line change:
nawk -v str=NEW '{print substr($0,1,4)""str""substr($0,8)}' infile
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-13-2007 12:19 PM
тАО03-13-2007 12:19 PM
Re: data manipulation in the file
>Ralph: I don't think that you can modify data in a file without opening it
I can only assume that Reen@ meant the Windows open (run an editor or other magic program based on suffix) and not the nerd definition of open a file.
- Tags:
- open
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-13-2007 12:32 PM
тАО03-13-2007 12:32 PM
Re: data manipulation in the file
Dennis wrote:
> I can only assume that Reen@ meant the Windows open (run an editor or other magic program based on suffix) and not the nerd definition of open a file.
Yes, of course. Unless you can *open* a file, how else can you expect any process to *read* a stream of octets to perform any match and/or substitution!?!
Depending upon the language, an implicit open() may be performed with a read() or write(), but that is purely under-the-covers slight-of-hand. The '-p' Perl switch is actually performing an open() for the file name(s) specified as arguments to the script so this too counts as an open(). Ditto for the 'sed' and the 'awk' solutions.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-13-2007 03:45 PM
тАО03-13-2007 03:45 PM
Re: data manipulation in the file
I have attached the file.
I dont want the change to be done for all lines.
Only once i want the 5th,6th and 7th character to be replaced with say "AIR".
I have to do this change for many files. And these 3characters will be different for different files.
So, i wont know the characters to be replaced before hand itself.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-13-2007 05:46 PM
тАО03-13-2007 05:46 PM
Re: data manipulation in the file
(Then you say you want it done for only the first line.)
$ sed -e '1s/^\(....\).../\1AIR/' file
This will create a new file, changing only the first line. You would need to save the output and rename it to the original.
for file in $*; do
sed -e '1s/^\(....\).../\1AIR/' $file > $file.new
mv $file.new $file
done
If the original is read-only, use "mv -f" above.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-13-2007 06:31 PM
тАО03-13-2007 06:31 PM
Re: data manipulation in the file
what does ^\(....\)... mean?
is it the range?
5th,6th and 7th character....how do i specify?:(
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-13-2007 06:50 PM
тАО03-13-2007 06:50 PM
Re: data manipulation in the file
I mentioned that initially. \( & \) assigns a number for the pattern inside, to the first 4 chars, then selects the next 3. "." means it can be an arbitrary char.
Then it puts the first 4 back with "\1", then your replacement string "AIR".
- Tags:
- regex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-13-2007 06:53 PM
тАО03-13-2007 06:53 PM
Re: data manipulation in the file
I got a simple solution for this.
cat file|cut -c5-7|read VAR1
sed "s/$VAR1/AIR/" file
will work out fine.
Thanks a lot for the help and patience.
I will do the further procedures and close the thread.:-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-13-2007 06:57 PM
тАО03-13-2007 06:57 PM
Re: data manipulation in the file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-13-2007 07:26 PM
тАО03-13-2007 07:26 PM
Re: data manipulation in the file
sed "s/$VAR1/AIR/" file
This depends on columns 5-7 of the first record not appearing ANYWHERE in the rest of the file.
My script only changes that one line and only those columns. You can fix part of it by using "1s/$VAR1/AIR/" and change cat to "head -1".
- Tags:
- evil cat