Search Results

Search: Posts Made By: summer_cherry
1,323
Posted By summer_cherry
users={} mark=[] with open("a.txt") as file: ...
users={}
mark=[]
with open("a.txt") as file:
for line in file:
line=line.replace("\n","")
if len(line)==0:
continue
if 'user=' in line:
user=line
else:
if user in users:...
899
Posted By summer_cherry
awk
awk 'BEING{lines=0}
{
if(NR%3==0){
print a
a=0
}
else{
a+=$3
print $0
}
lines=NR
}
END{
if(lines%3!=0)
print a
}' a
1,761
Posted By summer_cherry
python OR perl
python

import re
counter=1
keys={}
values={}
with open("a.txt") as file:
for line in file:
line=line.replace("\n","")
if re.match('=',line):
counter+=1
continue
items =...
8,441
Posted By summer_cherry
python
a=[]
with open("a.txt") as f:
for line in f:
words = line.split(",")
a.append(words[1::3])
for i in range(len(a)):
if(i==0):
pass
else:
for j in range(len(a[0])):
...
7,617
Posted By summer_cherry
python
with open("a.txt") as f:
for line in f:
line=line.replace("\n","")
words=line.split(",")
words=[words[0]]+words[len(words)-2:]+words[1:len(words)-2]
print(",".join(words))
3,763
Posted By summer_cherry
regular expression in perl is tailor-made for this kind of issue
while(<DATA>){
s/(?:[\[\]]|'(?=[^\[]*\]))//xg;
print;
}
__DATA__
"['1235','3234']","abcde","[1234]","['1235','3234']"
"'","abcde","[1235]","['1236','2234']"...
2,008
Posted By summer_cherry
perl code
my $pre;
while(<DATA>){
chomp;
if($.==1){
$pre = $_;
next;
}
else{
my @arr = split(" ",$_);
if($arr[1]%4==0){
print $pre,"\n";
print $_,"\n";
}
$pre = $_;
}
}...
1,327
Posted By summer_cherry
awk + python
awk:
gawk '{
if(NR==FNR){
_[$1]=$2
}
else{
if(/Storage/){
name=$NF
}
else{
if(NF==2){
l[name]+=_[$2]...
1,326
Posted By summer_cherry
awk, perl, python
awk
gawk -F"[|]" '{
if(NR==FNR){
_[$1]=sprintf("%s,%s",_[$1],$2)
}
else{
tmp=_[$1]
n=split(tmp,arr,",")
for(i=2;i<=n;i++){
print $0"|"arr[i]
}
}
}
' b a

perl
open my...
2,315
Posted By summer_cherry
you may try below perl
while(<DATA>){
chomp;
my @tmp = split(/\|/,$_);
if($. == 1){
@names = @tmp[1..$#tmp];
next;
}
else{
for(my $i=1;$i<=$#tmp;$i++){
push @{$hash{$tmp[0]}->{$i}}, $tmp[$i];
}...
6,484
Posted By summer_cherry
perl
local $/;
my $str = <DATA>;
my @arr = $str =~ /(<(\S+).*?<\/\2>)(?=.*school)/msg;
for(my $i=0;$i<=$#arr;$i=$i+2){
print '<?xml version="1.0"?>
<school>';
print "\n";
print $arr[$i],"\n";...
2,567
Posted By summer_cherry
awk
you may try below, let's see it is transpose.sh

transpose the whole file
!>transpose.sh file

transpose the file with column range 1 to 3
!>transpose.sh file 1,3

transpose the file with...
2,125
Posted By summer_cherry
perl is pretty easy to handle this
while(<DATA>){
if(/.*NAME="([^"]*).*Age="([^"]*).*D\.O\.B="([^"]*).*Gender="([^"]*).*/){
print $1," ",$2," ",$3," ",$4,"\n";
$age_hash{$2}++;
$gender_hash{$4}++;
...
2,416
Posted By summer_cherry
awk
awk '{
if(NR%2==1)
{
a=sprintf("%s %s %s",$1,$2,$3)
b=sprintf("%s %s %s",$4,$5,$6)
}
else{
print a" "$4" "$5" "$6
print $1" "$2" "$3" "b
}
}' yourfile
2,413
Posted By summer_cherry
how about you try below perl?
open $fh,"<f1.txt";
while(<$fh>){
chomp;
my @arr = split;
$hash{$arr[2]}->{'SEQ'}=$.;
$hash{$arr[2]}->{'VAL'}=$_;
$hash{$arr[2]}->{'GAP'}=10000;
}
open $fh2,"<f2.txt";
while(<$fh2>){...
3,527
Posted By summer_cherry
try perl below
while(<DATA>){
my @tmp = split;
if($.==1){
$pre=$tmp[1];
$cnt=1;
next;
}
else{
if($tmp[1] eq $pre){
$cnt++;
}
else{
$hash{$pre}->{$cnt}=1;
$cnt=1;...
919
Posted By summer_cherry
while(<DATA>){ next if $.==1; chomp; ...
while(<DATA>){
next if $.==1;
chomp;
my @tmp = split;
my @ids=split(",",$tmp[1]);
foreach(@ids){
print $tmp[0]," ",$_," ",$tmp[2]/($#ids+1),"\n";
}
}
__DATA__
4,829
Posted By summer_cherry
while(<DATA>){ my @tmp = split('"',$_,5); ...
while(<DATA>){
my @tmp = split('"',$_,5);
if(not exists $hash{$tmp[3]}){
$hash{$tmp[3]}=1;
print;
}
else{
if($hash{$tmp[3]}<2){
$hash{$tmp[3]}++;
print;
}
}...
5,136
Posted By summer_cherry
for i in FolderA;do ls ${i}/* | while read...
for i in FolderA;do
ls ${i}/* | while read file;do
tfile=`basename $file`
if [ -f FolderB/${tfile} ];then
rm FolderB/${tfile}
fi
done
done
3,112
Posted By summer_cherry
try below perl which is a little bit slow if your list is really long
open FH,"<listfile";
my @tmp = <FH>;
my @pat = map {s/\n//;$_} @tmp;
close FH;
open FH,"<filetobereplaced";
while(<FH>){
my $str = $_;
foreach my $pat (@pat){
my $tmp =...
5,245
Posted By summer_cherry
perl may help you some
my $tmp;
sub _comp(@@){
my $cnt;
my @a = @{$_[0]};
my @b = @{$_[1]};
for (my $i=2;$i<=$#a;$i++){
$cnt++ if $a[$i] != $b[$i];
}
return $cnt;
}
while(<DATA>){
if($.==1){
...
3,713
Posted By summer_cherry
perl may help you
my ($a,$b);
while(<DATA>){
chomp;
if(/^(".*?").* (\S*)$/){
$a=$1;
$b=$2;
print $_,"\n";
}
else{
print $a," ",$_," ",$b,"\n";
}
}
__DATA__
"A" 2 aa 34
3 ac
...
2,284
Posted By summer_cherry
perl
my $tmp;
while(<DATA>){
chomp;
if(/THEAD/){
$tmp=$_;
next;
}
elsif(/TDETL/){
print $_," ",$tmp,"\n";
}
}
__DATA__
FHEAD File1
THEAD TRANS1-blah
TDETL HI1
TDETL HI2
TDETL...
2,065
Posted By summer_cherry
my...
my %hash=(A,1,C,2,D,3,E,4,F,5,G,6,H,7,I,8,K,9,L,10,M,11,N,12,P,13,Q,14,R,15,S,16,T,17,V,18,W,19,Y,20);
open $fh,"<","a.spl";
my %hash1;
while(<$fh>){
my @tmp=split(/\*/,$_);
for(my...
71,039
Posted By summer_cherry
sed
Hi,

I think this one is easy.

sed -e '1,/OUTPUT/d' -e '/END/,$d' file
Showing results 1 to 25 of 26

 
All times are GMT -4. The time now is 08:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy