The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Remove first N bytes and last N bytes from a binary file on AIX. naveendronavall Shell Programming and Scripting 1 05-24-2008 12:06 PM
How to delete N bytes from the starting of the file from a C function??? jockey007 High Level Programming 2 11-15-2007 10:25 PM
file size in bytes is different in ftp and local pc umen UNIX for Dummies Questions & Answers 2 06-04-2007 05:58 PM
delete bytes from file Loriel Shell Programming and Scripting 6 04-13-2006 02:27 PM
Take a file from the system and put on tape and reset the file to 0 bytes JackieRyan26 UNIX for Dummies Questions & Answers 1 09-06-2001 06:08 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-16-2005
yankee428 yankee428 is offline
Registered User
  
 

Join Date: Feb 2005
Posts: 29
Rearrange bytes within a txt file

I have a text file with a very long list of dates, one date per line. Each date is in the same format yyyymmdd. I need the dates to be in mmddyyyy format.

This is part of a larger tcsh shell script.

I am just learning unix and came up with:

for each line in file
for each character in line
build a file using cut
use paste to rebuild the line in rearranged format mmddyyyy
rebuild total file from each linefile.

while this should work (i haven't built it yet), it's clearly a hack approach.

Can anyone point me in a better direction?

Last edited by yankee428; 06-16-2005 at 01:25 PM.. Reason: tab key went to submit, when I am used to indent.
  #2 (permalink)  
Old 06-16-2005
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
echo 'yyyymmdd' | sed 's/^\(....\)\(..\)\(..\)$/\2\3\1/'
  #3 (permalink)  
Old 06-16-2005
yankee428 yankee428 is offline
Registered User
  
 

Join Date: Feb 2005
Posts: 29
Hello again vgersh99,

So, how would i implement this in a script. My input file is called 4 and it looks like this

20161115
20190815
20200215
20200515
20200815
20210215

I want the output file say 4d to look like

11152016
08152019
02152020
...
  #4 (permalink)  
Old 06-16-2005
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
sed 's/^\(....\)\(..\)\(..\)$/\2\3\1/' 4 > 4d
  #5 (permalink)  
Old 06-16-2005
yankee428 yankee428 is offline
Registered User
  
 

Join Date: Feb 2005
Posts: 29
U ROCK!


...thanks again
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:08 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0