The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
not able to delete a file dr46014 UNIX for Dummies Questions & Answers 1 05-14-2008 10:51 PM
Why can't I delete this file? tphyahoo UNIX for Dummies Questions & Answers 3 07-17-2006 04:35 PM
how to delete record in file data with index in another file? zhynxn Shell Programming and Scripting 0 07-06-2006 12:03 AM
i want to delete a file based on existing file in a directory srivsn Shell Programming and Scripting 3 04-11-2006 04:38 AM
Get file from source server and delete the ftp file lweegp Shell Programming and Scripting 3 10-17-2005 02:53 AM

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 02-28-2007
dave043 dave043 is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 6
Delete the first 20k from 76k file

I'm a bit new at unix yet but I'm trying to write a script that will help me to delete the first 20k from a 76k file. So the end result will be a 56k file. I'm using sh. Please help

D
  #2 (permalink)  
Old 02-28-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,859
Code:
$ du -k f
76      f
$ dd if=f of=f_ bs=1k skip=20
56+0 records in
56+0 records out
$ du -k f_
56      f_
  #3 (permalink)  
Old 02-28-2007
dave043 dave043 is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 6
maybe I said this wrong on my post. I need to delete the FIRST 20k (size) from a file (lets say I don't know the file size) and the name of the file is test.log. How do go about deleting the first 20k from a file size that I do not know.

D
  #4 (permalink)  
Old 02-28-2007
sb008 sb008 is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 384
Quote:
Originally Posted by dave043
maybe I said this wrong on my post. I need to delete the FIRST 20k (size) from a file (lets say I don't know the file size) and the name of the file is test.log. How do go about deleting the first 20k from a file size that I do not know.

D
radoulov gave you the correct answer.

The block size is defined in k.
It says to skip the first 20 blocks, so 20 k.
The rest (all after the first 20k) is copied.
  #5 (permalink)  
Old 02-28-2007
dave043 dave043 is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 6
can I run this in a shell script? if so how do I do this?

D
  #6 (permalink)  
Old 02-28-2007
sb008 sb008 is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 384
Quote:
Originally Posted by dave043
can I run this in a shell script? if so how do I do this?

D
Depends on what you exactly want, you could make a script with 1 or 2 arguments.

With 1 argument you can specify the name of the file from which you want to cut of the first 20k, the new file will have the same name with ".new" added.

Code:
#!/usr/bin/ksh

dd if=${1} of=${1}.new bs=1k skip=20
Suppose we name this script "cut20k-v1.sh"
You would run it like "./cut20k-v1.sh <file>"

E.g.
Code:
./cut20k-v1.sh testfile
It would cut the first 20k from the file "testfile" and the resullt would be in the file "testfile.new"

You could create a script which takes 2 arguments. The first argument would be the name of the file from which you would like to cut off the first 20k and the second argument would be the name of the file with the first 20k missing.

Code:
#!/usr/bin/ksh

dd if=${1} of=${2} bs=1k skip=20
Suppose we name this script "cut20k-v2.sh"
You would run it like "./cut20k-v2.sh <infile> <outfile>"

E.g.
Code:
./cut20k-v2.sh testfile resultfile
It would cut the first 20k from the file "testfile" and the resullt would be in the file "tesiultfile"
  #7 (permalink)  
Old 02-13-2008
jankar jankar is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 2
I am new to scripting and am trying to do a similar thing;

I would like to take the first 20k out of a file, leave the rest of the file intact then output that 20k to a new file.

I am not sure how to do this.. Thanks for the help!
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 08:42 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