The UNIX and Linux Forums  


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
Awk not working due to missing new line character at last line of file pinnacle Shell Programming and Scripting 2 05-07-2009 10:51 PM
error while replacing a string by new line character in sed millan Shell Programming and Scripting 8 04-28-2009 06:06 AM
Replacing a character string in a file rjsha1 Shell Programming and Scripting 13 04-11-2009 02:07 PM
Replacing a character in a line Usha Shastri UNIX for Dummies Questions & Answers 2 04-02-2009 03:08 AM
Replacing character in file with null value HLee1981 Shell Programming and Scripting 18 07-18-2006 02:33 PM

Reply
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 05-28-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,365

In a slightly simpler form it may be easier to understand:


Code:
awk '{ print substr( $0 , 1, length-1 ) "Z" }'

  #2 (permalink)  
Old 05-28-2009
durden_tyler's Avatar
durden_tyler durden_tyler is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2009
Posts: 547
Alternatively, if you have perl:


Code:
$
$ perl -ne 'substr($_,-2,1)="Z"; print' result.dat
1.11a,Test result for scenario 1,1 2 3 4,Z
1.12b,Test result for scenario 2,incomplete,Z
1.13,Test result for scenario 3, 4 5 6,Z
$

tyler_durden
  #3 (permalink)  
Old 05-28-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
Quote:
Originally Posted by panyam
. "Z" is the the character tht u want to be the last one so he is printing ..U can print wht evr character u wish at the end.
Hello,

Per our forum rules, all users must write in English, use semi-formal or formal English language and style, and correct spelling errors.

The reason for this is that most software and operating systems are written in English and these are software related technical forums.

In addition, nearly 95% of all visitors to this site come here because they are referred by a search engine. In order for future searches on your post (with answers) to work well, you need to spell correctly!

So, as a benefit and courtesy to current and future knowledge seekers, please be careful with your language, check your spelling and correct your spelling errors. You might receive a forum infraction if you don't pay attention to this.

Also, do not write in cyberpunk or abbreviated chat style under any circumstances and do not use profanity. This is not a chat room, it is a formal knowledge base to serve you and everyone, of all ages and cultural backgrounds.

Thanks!

The UNIX and Linux Forums
  #4 (permalink)  
Old 05-28-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,555
people have shown you how to use awk already. last field value stands for $NF, second field stands for $2. therefore, pls try and show some code. Read the awk docs especially.
  #5 (permalink)  
Old 05-29-2009
protocomm protocomm is offline
Registered User
  
 

Join Date: Mar 2009
Location: france, montpellier
Posts: 150
sed 's/.$/z/'

this expression allow to replace last character by z

-----Post Update-----

try1 is your file

cat try1 | while read line; do res=$(echo $line | awk -F "," '{print $NF}');if [ $res = "p" ];then var=$(echo $line | awk -F "," '{print $2}');echo $var;fi; done

-----Post Update-----

try1 is your file

cat try1 | while read line; do res=$(echo $line | awk -F "," '{print $NF}');if [ $res = "p" ];then var=$(echo $line | awk -F "," '{print $2}');echo $var;fi; done
  #6 (permalink)  
Old 05-29-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,555
Quote:
Originally Posted by protocomm View Post

Code:
cat try1 | while read line; do res=$(echo $line |  awk -F "," '{print $NF}');if [ $res = "p" ];then var=$(echo $line | awk -F "," '{print $2}');echo $var;fi; done
no need while loop, cat and those extra if/else and awk. Just one awk command can do it.
  #7 (permalink)  
Old 05-29-2009
protocomm protocomm is offline
Registered User
  
 

Join Date: Mar 2009
Location: france, montpellier
Posts: 150
certainly, but i haven't good knowledges in command awk.
I'm a beginner.
Reply

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 01:45 AM.


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