nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

Spliting files each line by using token

This is a discussion on Spliting files each line by using token within the Shell scripting forums, part of the Development/Scripting category; Dear Friends , Following script is very much helpful for splitting a file contents ..... If any comments ....pls correct ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 12-08-2007, 03:00 PM
anilvrathod's Avatar
Junior Member
User
 
Join Date: Dec 2007
Location: Pune
My distro: Red Hat
Posts: 13
Rep Power: 0
anilvrathod is on a distinguished road
Smile Spliting files each line by using token

Dear Friends ,
Following script is very much helpful for splitting a file contents .....
If any comments ....pls correct as per your knowledge ..

This script is used for the file which content are as follow . You can modify this script as per your application and file structure .
Note Red color indicate modification

suppose your file have the following structure and you want to splitting each line and words of lines then following script is helpful

#cat databasefile.txt
A1005184|361371|24|462132||2002-09-27 02:38:53+00|csym|20020927
A1005183|361371|24|574452||2002-09-27 02:40:27+00|mp3|20020927
A1005184|361371|24|462132||2002-09-27 02:40:27+00|mp3|20020927
A1032533|211189|24|889785|223|2004-05-24 21:34:31+00|ips|20040524
A1032532|363029|24|454995|120|2004-05-24 21:34:28+00|mp3|20040524


Code:
vi file_content_split.sh 
     1 path="
Code:
/path_of_databasefile.txt"
      2
      3 echo "Original file "
      4 cat $path
      5 echo "***************************************"
      6
      7 for text_file in $path
      8   do
      9              cat  $path  | tr  "|"  "*" > tmp     #(translate pipe[|] into  *)
     10   done
     11
     12
     13  echo "#####################################"
     14  echo "Translated File ---------------------"
     15  cat tmp
     16   echo "------------------------------------"
     17   tmp_file="/home/kalinga/sbin/tmp"
     18
     19    IFS=*
     20     while read  read_vfile_id read_cust_id read_priority_tat read_vfile_size read_rec_duration read_dt        _created read_ext read_datefolder
     21
     22     do
     23       echo "***********"
     24       echo "read_vfile_id:" ${read_vfile_id}
     25       echo "read_cust_id:"${read_cust_id}
     26       echo "read_priority_tat :"${read_priority_tat}
     27       echo "read_vfile_size:" ${read_vfile_size}
     28       echo "read_rec_duration:" ${read_rec_duration}
     29       echo "read_dt_created:"${read_dt_created}
     30       echo "read_ext:"${read_ext}
     31       echo "read_datefolder:"${read_datefolder}
     32    done < $tmp_file  > anil.txt
     33    echo  "Do one thing....... Do it Well ! ---------- Linus Torwald"
     34    cat anil.txt

Anil V. Rathod
Linux System Administrator
Kalinga Data Link Pvt.Ltd. Pune
Cell No. 9860062917

Last edited by anilvrathod; 12-11-2007 at 02:11 PM..
Reply With Quote
Sponsored Links
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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

Similar Threads

Thread Thread Starter Forum Replies Last Post
HPUX Unix comparing 2 large files line by line raj HP-UX 1 02-11-2008 06:20 PM
Command line remote access angelus_kit Networking, Firewalls and Security 7 09-05-2007 07:30 PM
Omit the first line in a file c341 Shell scripting 4 12-29-2006 03:07 PM
SED pass a output line to another cillo Shell scripting 6 11-01-2006 02:59 PM
for do loop in solaris one line Solaris/OpenSolaris 1 01-09-2006 02:35 PM


All times are GMT +5.5. The time now is 08:57 PM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36